Q:

C# program to demonstrate the use of reflection to get namespace and base-type

0

C# program to demonstrate the use of reflection to get namespace and base-type

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate reflection to get namespace and base-type is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

// C# program to demonstrate the use of reflection 
//to get namespace and base type.

using System;
using System.Reflection;

class RefDemo
{
    static void Main()
    {
        Type type;
        
        type = typeof(int);
        Console.WriteLine("Data Type Name : "+ type.Name        );
        Console.WriteLine("Full Type Name : "+ type.FullName    );
        Console.WriteLine("Namespace      : "+ type.Namespace   );
        Console.WriteLine("Base Type      : "+ type.BaseType    );
    }
}

Output:

Data Type Name : Int32
Full Type Name : System.Int32
Namespace      : System
Base Type      : System.ValueType
Press any key to continue . . .

Explanation:

Here, we created a class RefDemo. Here, we imported the System.Namespace to get system type namenamespace, and base-type using predefined properties.

The RefDemo class contains the Main() method. In the Main() method, we created a reference from the Type class.

type = typeof(int);

Here, reference type is initialized with reference returned by the typeof() operator, and then we printed system type-name, full type-name, namespace, and base-type using predefined properties.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to print class names created in the pro... >>
<< C# program to implement hierarchical inheritance u...