Junior — Middle
Kas saaksite selgitada, mida mõistetakse programmeerimises refleksiooni all?
sobes.tech AI
Vastus AI-lt
Reflection in programming is the ability of a program to explore and modify its structure and behavior at runtime. In C#, reflection allows obtaining information about object types, methods, properties, and attributes during program execution.
Example of using reflection in C#:
using System;
using System.Reflection;
class Program
{
static void Main()
{
Type type = typeof(String);
Console.WriteLine("Methods of the String class:");
MethodInfo[] methods = type.GetMethods();
foreach (var method in methods)
{
Console.WriteLine(method.Name);
}
}
}
This code lists all methods of the String class. Reflection is useful for dynamically invoking methods, creating objects, and analyzing types without knowing their details at compile time.