mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-20 12:48:39 +00:00
Implement Castclass
This commit is contained in:
23
WoofWare.PawPrint.Test/sourcesPure/CastClassGenerics.cs
Normal file
23
WoofWare.PawPrint.Test/sourcesPure/CastClassGenerics.cs
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user