Logo 
Search:

C# FAQ

Submit Interview FAQ
Home » Interview FAQ » C#RSS Feeds

So I can pass an instance of a value type to a method that takes an object as a parameter?

  Shared By: Landra Schmidt    Date: Oct 16    Category: C#    Views: 962

Answer:

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

Share: 
 



Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: