Skip to content

Void write (object obj);

Joy

Asked May 8, 2007, 5:57 PM EDT1 answer
Share
LinkedInX
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 Gold
    0
    Hi,

    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:

    C#
    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);
    }
    0