creates instances of a value and a reference type : Function Parameters « Language Basics « C# / C Sharp






creates instances of a value and a reference type

 

using System;

class Starter {

    static void Main() {
        int localvalue = 5;
        MyClass objZ = new MyClass();
        DisplayType(localvalue);
        DisplayType(objZ);
    }

    static void DisplayType(object parameterObject) {
        Type parameterType = parameterObject.GetType();
        string name = parameterType.Name;
        Console.WriteLine("Type is " + name);
        if (name == "MyClass") {
            ((MyClass)parameterObject).Display();
        }
    }

}

class MyClass {

    public void Display() {
        Console.WriteLine("MyClass::Display");
    }
}

 








Related examples in the same category

1.Reference, output and value parameters.
2.Passing parameters to methods
3.Pass valuel by pointer
4.ref pointer parameter
5.Arrays as Function Returns and Parameters
6.Use ref to mark an object parameter
7.Use out to mark an object parameter
8.Pass integer by reference