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
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Mike GoldRank #50 · 30.6K pointsPosted May 9, 2007, 12:07 PM EDT
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); }