Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Introduction to Reflection | Generics & Reflection
Advanced C# with .NET

bookIntroduction to Reflection

Reflection is a powerful feature of C# which allows the program to interact with types and objects runtime.

Reflection is not a specific kind of a syntax or a method which we use, instead, it is a set of methods and features which can be used to find out useful information of different types at the run time.

For-example, using Reflection, we can

  • Get a list of all the public properties of a class;
  • Get a list of all the public methods of a class;
  • Indirectly invoke methods of an object;
  • Dynamically create instances of a class;
  • Get the parent class of any specific type;

The classes that enable us to perform reflection are provided in the System.Reflection namespace. Therefore, we need to import System.Reflection before using reflection in our programs:

One very common part of reflection we use in our programs is the GetType method. This method returns the type of any object.

index.cs

index.cs

copy
12
int a = 7; Console.WriteLine($"{a.GetType()}");

Output:

System.Int32
question mark

What is reflection in C#?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 6

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Awesome!

Completion rate improved to 3.7

bookIntroduction to Reflection

Свайпніть щоб показати меню

Reflection is a powerful feature of C# which allows the program to interact with types and objects runtime.

Reflection is not a specific kind of a syntax or a method which we use, instead, it is a set of methods and features which can be used to find out useful information of different types at the run time.

For-example, using Reflection, we can

  • Get a list of all the public properties of a class;
  • Get a list of all the public methods of a class;
  • Indirectly invoke methods of an object;
  • Dynamically create instances of a class;
  • Get the parent class of any specific type;

The classes that enable us to perform reflection are provided in the System.Reflection namespace. Therefore, we need to import System.Reflection before using reflection in our programs:

One very common part of reflection we use in our programs is the GetType method. This method returns the type of any object.

index.cs

index.cs

copy
12
int a = 7; Console.WriteLine($"{a.GetType()}");

Output:

System.Int32
question mark

What is reflection in C#?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 6
some-alt