Kamis, 08 November 2007

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;
}
}

Tidak ada komentar: