// The int has assumed a new identity!
int myInt = 12345678;
myInt.DisplayDefiningAssembly();
// So has the DataSet!
System.Data.DataSet d = new System.Data.DataSet();
d.DisplayDefiningAssembly();
// And the SoundPlayer!
System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
sp.DisplayDefiningAssembly();
// Use new integer functionality.
Console.WriteLine("Value of myInt: {0}", myInt);
Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());
myInt.Foo();
myInt.Foo("Ints that Foo? Who would have thought it!");
bool b2 = true;
// Error! Booleans don't have the Foo() method!
// b2.Foo();
Console.ReadLine();
}
Figure 13-2 shows the output.
C H A P T E R 1 3
■
C # 2 0 0 8 L A N G U A G E F E AT U R E S
426
8849CH13.qxd 10/2/07 12:42 PM Page 426
Figure 13-2.
Extension methods in action
Do'stlaringiz bilan baham: |