Reflection in C# is a powerful feature that allows you to inspect the metadata of types in your application at runtime. It enables you to dynamically create instances of types, bind to properties, methods, and events, and even invoke methods or access fields and properties without knowing their names at compile time. This is particularly useful for scenarios like plugin development, serialization, and dependency injection.
using System;
using System.Reflection;
public class Example
{
public void SayHello()
{
Console.WriteLine("Hello, World!");
}
}
class Program
{
static void Main(string[] args)
{
// Creating an instance of Example class
Type exampleType = typeof(Example);
object exampleInstance = Activator.CreateInstance(exampleType);
// Getting and invoking the SayHello method
MethodInfo methodInfo = exampleType.GetMethod("SayHello");
methodInfo.Invoke(exampleInstance, null);
}
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?