Sunday, 28 April 2013

So I can pass an instance of a value type to a method that takes an object as a parameter? | C#.Net Interview Questions

Yes.
For example:
class CApplication
{
public static void Main()
{
  int x = 25;
  string s = "fred";
  DisplayMe( x );
  DisplayMe( s );
}
static void DisplayMe( object o )
{
System.Console.WriteLine( "You are {0}", o );
 }
 }
This would display:
 You are 25
  You are fred

No comments: