void write (object obj);
Hi i am new to c#, i can't understand the following function statement
void write (oject obj); can an object be sent as a parameter to any method
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mike GoldPosted May 9, 2007, 4:07 PM
An object is the root (parent) class for all objects, so yes, you can pass any instance of a class: value type (int, float, etc.) or reference type (string, myOwnClass, ArrayList) and it will take the value.
Below is an example of some of the types of things you can pass to an object:
static void Main(string[] args)
{
write(1);
int i = 2;
write(i);
write("hello");
string response = "good-bye";
write(response); Console.ReadLine();
} static void write(object test)
{
Console.WriteLine("Var = {0}", test);
}