Jumat, 23 November 2007

Jawaban Quiz PT.Gudang informatika


using System;


using System.Collections.Generic;


using System.Text;


namespace ConsoleApplication6


{


class Program


{


public static int maxangka = 999;


public static int AlphabetMax = 90;


public static int AlphabetMin = 65;



static void Main(string[] args)


{


// SoalNo1();


//Alphabet 65-90


SoalNo1();


Console.ReadLine();


SoalNo2(000);


Console.ReadLine();


}



static void SoalNo2(int angkanya)


{


if (angkanya <= 999+3)


{


if (angkanya <= maxangka)


{


string tmpstr = angkanya.ToString().PadLeft(3, Convert.ToChar("0"));


PrintHurufOnebyOne(65);


Console.Write(tmpstr);


Console.Write(",");


}


if (angkanya==1000)


{


PrintHurufOnebyOne2(66);


}


if (angkanya == 1001)


{


PrintHurufOnebyOne3(66);


}


if (angkanya == 1002)


{


PrintHurufOnebyOne4(66);


}



 




SoalNo2(angkanya + 1);


}


}



static void PrintHurufOnebyOne(int huruf)


{


if (huruf >= 65 && huruf <= 90)


{


char theletter = Convert.ToChar(huruf);


string tmpstr = theletter.ToString().PadLeft(3, Convert.ToChar("A"));


Console.Write(tmpstr);


}


}


static void PrintHurufOnebyOne2(int huruf)


{


if (huruf > 65 && huruf <= 90)


{


char theletter = Convert.ToChar(huruf);


string tmpstr = "AA" + theletter.ToString();


Console.Write(tmpstr);


Console.Write("999");


Console.Write(",");


PrintHurufOnebyOne2(huruf + 1);


}


}


static void PrintHurufOnebyOne3(int huruf)


{


if (huruf > 65 && huruf <= 90)


{


char theletter = Convert.ToChar(huruf);


char minalphabet = Convert.ToChar(AlphabetMin);


char maxalphabet = Convert.ToChar(AlphabetMax);


string tmpstr = minalphabet.ToString() + theletter.ToString() + maxalphabet.ToString();


Console.Write(tmpstr);


Console.Write("999");


Console.Write(",");


PrintHurufOnebyOne3(huruf + 1);


}


}


static void PrintHurufOnebyOne4(int huruf)


{


if (huruf > 65 && huruf <= 90)


{


char theletter = Convert.ToChar(huruf);


string tmpstr = theletter.ToString().PadRight(3, Convert.ToChar(AlphabetMax));


Console.Write(tmpstr);


Console.Write("999");


Console.Write(",");


PrintHurufOnebyOne4(huruf + 1);


}


}


private static void SoalNo1()


{


int @switch = 5;


int banding = @switch;


int max = 1000;


string delimiter = "*";


for (int a = 1; a <= 1000; a++)


{


Console.Write(a);


if (a == banding)


{


int coba = (@switch == 3) ? @switch = 5 : @switch = 3;


Console.Write(delimiter);


banding += @switch;


}


}


Console.ReadLine();


}


}


}

Senin, 19 November 2007

Verbatim


public class Verbatim


{


static void Main()


{


//all the preceding after @ is not treated as escape character


string fileLocation = @"c:\datafile.txt";


Console.WriteLine("File is located at {0}",


fileLocation);


//booking a word in all the words already booked in c#


int @for = 12;


Console.WriteLine(@for.ToString());


Console.ReadLine();


}


 


}

Escape Characters


namespace PreProcessorsDirective


{


class Class1


{


class HelloWorld


{


static void Main()


{


Console.Write("\u0048\u0065\u006C\u006C\u006f\n");


Console.Write("\x77\x6F\x72\x6c\x64\x21\b");


Console.ReadLine();


}


}


 


}


}

Numeric Literal and Hexadecimal


class NumericLiteral


{


static void Main()


{


//numeric literal


float unitprice = 123.45F;


double cobacoba = 3.256;


decimal coba2 = 3.256M;


//hexadecimal


int sixteen = 16;


int sixteeninDecimal = 0x10;


 


// end of mt940 msg is char(0x1A)


// if (line.Length == 1 && line[0] == 0x1A)


//0x1A equals 26


}

PreProcessorsDirective


#define debugging


using System;


using System.Collections.Generic;


using System.Text;


namespace PreProcessorsDirective


{


class PreProcessorsDirective


{


#if debugging


static void Write()


{


Console.WriteLine("Debugging.>>");


}


#endif


#pragma warning disable 219


#line 10


static void Main(string[] args)


{


int a = 5; //219 Warning


#if debugging


Write();


#endif


}


}


}

Garbage Collector

Now i won't deal with the theory.
just a brief look on code.
To force GC to collect the candidate to dispose

GC.collect();

GC.WaitForPendingFinalizers();
This will make GC wait for all of the finalizer of every suspected object to be called

You can override finalizer with short key ~
~thenameoffinalizer()
{
//do something
}

The right thing to write on the so When calling finalizer also call dispose
~Thing()
{
Dispose();
//Do something on finalizer
}
can do try catch, if error register again to finalize with this command
GC.ReRegisterForFinalize(t);

There are also to check the total memory method on GC.
long G =GC.GetTotalMemory(true);

Jumat, 16 November 2007

Live from Lumpur Lapindo, Sidoarjo

I've gone to this Lumpur lapindo, at porong sidoarjo.penulis adalah org jkt yang hanya mendengar dari berita sblmnya.
sekarang tempat ini sudah menjadi tempat wisata. parkir motor 2000, masuk 3000/org.
disana pada tepian pertama anda akan melihat 2 atau 3 kolam besar di bawah anda. ada yang satu kolam itu sudah menjadi keras, seperti tanah kering retak2.dan anda lihat
ada penangkal2 petir , ujung tiang masjid.2 atau 3 desa lenyap di bawah kolam itu. lalu dgn membayar 10.000 anda di antar ke 2 titik, ke kolam utama dan ke sebelah kanan, tempat semburan baru. di Tempat semburan baru.. anda lihat gelembung2 . "Semenjak bola2 beton di lemparkan ke pusat semburan, tanah itu kan seperti rongga, jadi malah di kolam2 bawahnya terjadi pusat semburan baru(blub blub blup)" keterangan tour guide.
Tour guide juga menunjukkan rumah Marsina kasus marsina yg memperjuangkan hak teman2nya dan ditembak oleh TNI "mungkin ini pembalasan Marsina" ,cetus tourguide.Juga ada rumah doyok yang tenggelam.
di samping kiri kolam utama anda lihat bahwa tanggulnya jebol, atas nya keras tapi tengah2 mengalir terus lumpurnya dan juga Pipa AWAL yang jebol/meledak, asal mula lumpur. "LUMPUR INI AKAN TERUS MENGALIR 30 tahun lagi"
Sepanjang jalan porong kini sudah seperti Kota hantu, tidak berpenghuni , bank2 tidak beroperasi dan Flyover jalan tol di hancurkan, dan bau belerang / sulfur di mana2.
semua tanah di sana di black list gak bisa jadi pinjaman.
Menurut tour guide yg jg adlh warga sidoarjo yg menjadi korban, "Banyak warga yang sudah mati Karena stress , terutama yang tua2".

rencana ingin dialirkan ke kali porong diprotes warga, bygkan. . .kalo masuk ke kali

Kemanakah akan dialirkan lumpur ini?? 30 tahun lagi?
Berduka untuk Porong . . . .

Kamis, 15 November 2007

Code Generator Example


// Set up our assembly and module builders:


string outFilename = "foo.exe";


AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(


new AssemblyName("foo"), AssemblyBuilderAccess.Save,


AppDomain.CurrentDomain.Evidence);


ModuleBuilder mb = ab.DefineDynamicModule(ab.FullName, outFilename, false);


// Create a simple type with one method:


TypeBuilder tb = mb.DefineType("Program",


TypeAttributes.Public | TypeAttributes.Sealed, typeof(object));


MethodBuilder m = tb.DefineMethod("MyMethod",


MethodAttributes.Public | MethodAttributes.Static);


// Now emit some very simple "Hello World" code:


ILGenerator ilg = m.GetILGenerator();


ilg.Emit(OpCodes.Ldstr, "Hello, World!");


ilg.Emit(OpCodes.Call,


typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }));


ilg.Emit(OpCodes.Ret);


// Lastly, create the type, set our entry point, and save to disk:


tb.CreateType();


ab.SetEntryPoint(m);


ab.Save(outFilename);


 


For all of you who have example on LGC for 2.0 Please Post!!!

Drag n Drop on Control

Set the control property Allowdrop=true.


When mouse down thecontrol.Dodragdrop(object,DragdropEffectsEnum)


DragdropEffects.Copy | Move | ALL | None | Link | Scroll


and then on the control that you want to drop


put the logic on Drag Enter And Drag Drop


set the drag enter e.effect


and put the logic when data is drop.


 


 

Rabu, 14 November 2007

Validating XML with DTD or XSD

public void ValidateXMLagainstDTD(Stream thestream)


{


XmlTextReader reader = new XmlTextReader(thestream);


XmlValidatingReader validator = new XmlValidatingReader(reader);


validator.ValidationType = ValidationType.DTD;


validator.ValidationEventHandler += new ValidationEventHandler(DTDValidationEventHandler);


while (validator.Read())


{


//add something logical here


}


validator.Close();


if (Isvalid)


Console.WriteLine("Document is valid");


else


Console.WriteLine("Document is Invalid");


Console.ReadLine();


}


public void DTDValidationEventHandler(object sender,


ValidationEventArgs args)


{


this.Isvalid = false;


Console.WriteLine("Validation event\n" + args.Message);


}

Create XML through XmlWriterSettings => the fastest,efficient way instead using DOM


public static MemoryStream CreateXMltoStream(string emailsubject,string emailfrom,string emailto)


{


MemoryStream stream=new MemoryStream();


XmlWriterSettings thesettings = new XmlWriterSettings();


//writing to stream default is UTF8


Encoding x=System.Text.Encoding.GetEncoding("ISO-8859-1");


thesettings.Encoding = x;


thesettings.Indent = true;


//Write the header


thesettings.OmitXmlDeclaration = false;


thesettings.NewLineOnAttributes = true;


using (XmlWriter writer = XmlWriter.Create(stream, thesettings))


{


writer.WriteRaw(@"<!DOCTYPE MEDVRI_1 SYSTEM ""MEDVRI_1.dtd"">");


writer.WriteStartElement("MEDVRI_1");


writer.WriteStartElement("email");


writer.WriteStartElement("email.subject");


writer.WriteValue(emailsubject);


writer.WriteEndElement();


writer.WriteStartElement("email.from");


writer.WriteValue(emailfrom);


writer.WriteEndElement();


writer.WriteStartElement("email.to");


writer.WriteValue(emailto);


writer.WriteEndElement();


writer.WriteEndElement();


writer.WriteEndElement();


//free the memory


writer.Flush();


writer.Close();


return stream;


}


 


 

WSE 3.0

What is the use of WSE? WSE create a filter and security policy making kind of tunnel so what ever request go to that pipeline.


It can secure the server, and client app. make sure each of them using the correct policy.


there are usernamepolicy , certificate policy, and you can add an authorize one. Can do a custom policy too


What is good on learning this is WSE Hands on Lab,you’ll find the basic and advanced.


 

Minggu, 11 November 2007

List

What is actually List , Generic or T, it means that this has not yet been bound to a type argument.What differs from List for example, is that the List means it has been fully constructed,each of it's parameter has been bound.

Partially constructed generic type example:
class StringKeyDictionary : Dictionary { }

Jumat, 09 November 2007

How Does Reflection Detect This Paramater is Generic?

namespace PrintTypeParamsss
{
class Program
{
static void Main(string[] args)
{
PrintTypeparams(typeof(List<>));
PrintTypeparams(typeof(List));
PrintTypeparams(typeof(Dictionary));
PrintTypeparams(typeof(Dictionary));
PrintTypeparams(typeof(Nullable<>));

Console.ReadLine();
}
static void PrintTypeparams(Type t)
{
Console.WriteLine(t.FullName);
foreach (Type ty in t.GetGenericArguments())
{
Console.WriteLine("--> {0} {1} {2}",
ty.FullName,
ty.IsGenericParameter,
ty.IsGenericParameter ? ty.GenericParameterPosition : 0);
};

}
}
}

Property Info

namespace PropertyInfossss
{
public class Test
{
private string _Test;
public string Name
{
get { return _Test; }
set { _Test = value; }
}
}
class Program
{


static void Main(string[] args)
{
PropertyInfo a=typeof(Test).GetProperty("Name");
Console.WriteLine("Read:" + a.CanRead + " Write:" + a.CanWrite + " Type:" + a.PropertyType);
MethodInfo theSetMethod = a.GetSetMethod();
MethodInfo theGetMethod = a.GetGetMethod();
MethodBody theSetMethodBody= theSetMethod.GetMethodBody();
MethodBody theGetMethodBody= theGetMethod.GetMethodBody();


}
}

PE and Platform Kinds

Assembly a = Assembly.GetExecutingAssembly();
Module m = a.ManifestModule;
PortableExecutableKinds peKinds;
ImageFileMachine imageFileMachine; m.GetPEKind(out peKinds, out imageFileMachine);
if ((peKinds & PortableExecutableKinds.ILOnly) != 0)
{
// Assembly is platform independent.
}
else
{
// assembly is platform dependent
switch (imageFileMachine)
{
case ImageFileMachine.I386:
// i386, x86, IA-32, ... dependent.
break;
case ImageFileMachine.IA64:
// IA-64 dependent.
break;
case ImageFileMachine.AMD64:
// AMD-64, x64 dependent.
break;
}

}

Kamis, 08 November 2007

Pepatah Kuno Dinasti Ming

Haiaa . .
Banyak belajal banyak lupa
Sedikit belajal sedikit lupa
Pu yau Belajal Lupa semuanya ...
Haiaa
Jadi oe pili yang mana?
Kesimpulan ini kalo dibalik????
Belajar itu hanya Memberi kita gambaran, dan konsep, dan di halaman mana atau di buku mana atau di referensi mana.
Tapi Praktek itu Menerapkan Apa yang kita pelajari jadi nyata.. semakin mengukuhkan apa yang ada di otak kita.

Salam,


Tzu she

O'Desk Test

I passed the O'desk test on C# 66 or 70%
dunno lah. . . . what's the use
just for iseng2.

Aneka makanan Reflection,Methodinfo,MethodBody,Constructorinfo

public class Cobacoba
{
private void Lemparbatu(string batunya, int jumlahnya)
{

}
public int LemparbatuReturn(string batunya, int jumlahnya)
{
int hak = 0;
string tipenya = "sepatu";
try
{
Console.WriteLine("Lemparbatu return executed,Nilai params=>batunya: {0} jumlahnya: {1}", batunya, jumlahnya);
return jumlahnya;
}
catch (InvalidProgramException ex)
{

}
catch (ApplicationException eb)
{ }
return jumlahnya;
}
}
class Program
{
static void Main(string[] args)
{
MethodInfo m = typeof(Cobacoba).GetMethod("LemparbatuReturn");
//nyari tipe return
Type tipereturnnya = m.ReturnType;
Console.WriteLine(tipereturnnya.ToString());
//nyari tipe parameter
foreach (ParameterInfo param in m.GetParameters())
{
Console.WriteLine(param.Name + " " + param.ParameterType.ToString());
}
/*this shows the invoke Member*/
Cobacoba ttg=new Cobacoba();
MethodInfo method = typeof(Cobacoba).GetMethod("LemparbatuReturn");
/*the usage of methodbody*/
MethodBody mb= method.GetMethodBody();
IList x = mb.LocalVariables;
IList n = mb.ExceptionHandlingClauses;
/*the usage of Constructor Info*/
ConstructorInfo ci = typeof(string).GetConstructor(new Type[] { typeof(char[]) });
string s = (string)ci.Invoke(new object[] { new char[] { 'H', 'E', 'L', 'L', 'O' } });
Console.WriteLine(s);
Type tem = ttg.GetType();
string f="granit";
int g=3;
object[] t=new object[2];
t[0]=(Object) f;
t[1]=(Object) g;
try
{
tem.InvokeMember("LemparbatuReturn", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, ttg, t);
}
catch (TargetInvocationException ex)
{
//do something Here
}
Console.ReadLine();
}
}

Activator object and General method Instancied

public class Customer
{
string name;
string address;
int Phonenumber;
}
class Program
{
static void Main(string[] args)
{
//this is better than d because Karena gak perlu super casting dan lebih gampang ketik
Customer c = Activator.CreateInstance();
//this is slower
Customer d = (Customer)Activator.CreateInstance(typeof(Customer));
Customer e=CreateandLognewobject("Dangdang");
Console.ReadLine();
}
static T CreateandLognewobject(string s)
{
T t = Activator.CreateInstance();
Console.WriteLine("Created new object '{0}' ; {1}", t, s);
return t;
}
}

Jumat, 02 November 2007

Gloria , Manukan

Ayam penyet luarbiasa garingnya
dan enak dan lembutnya.
dipadukan dengan Juice ALpukat yg Kental ,Ukuran gls besar,cucu coklat yg mantabs.
Luar biasa