Implement Castclass

This commit is contained in:
Smaug123
2025-06-27 11:41:41 +01:00
parent 5cf0789439
commit 1ebcd0b4f5
42 changed files with 856 additions and 132 deletions

View File

@@ -0,0 +1,23 @@
public class Program
{
public class Container<T>
{
public T Value { get; set; }
}
public static int Main(string[] args)
{
Container<int> intContainer = new Container<int> { Value = 42 };
// Cast generic type to object
object obj = (object)intContainer;
// Check type and cast back
if (obj is Container<int> container)
{
return container.Value;
}
return 0;
}
}