Created
December 26, 2022 15:32
-
-
Save nithinshiriya/b61ef0ef7c934a4c82ff08bd7c953770 to your computer and use it in GitHub Desktop.
An unmanaged constructed type is a data type that is generated at runtime in .NET programming and is not monitored by the garbage collector. These types are often used in situations where the type is only needed within a single method or block of code and has a limited lifespan. The System.Reflection.Emit namespace is used to create these types …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public struct Coords<T> | |
{ | |
public T X; | |
public T Y; | |
} | |
public class UnmanagedTypes | |
{ | |
public static void Main() | |
{ | |
DisplaySize<Coords<int>>(); | |
DisplaySize<Coords<double>>(); | |
} | |
private unsafe static void DisplaySize<T>() where T : unmanaged | |
{ | |
Console.WriteLine($"{typeof(T)} is unmanaged and its size is {sizeof(T)} bytes"); | |
} | |
} | |
// Output: | |
// Coords`1[System.Int32] is unmanaged and its size is 8 bytes | |
// Coords`1[System.Double] is unmanaged and its size is 16 bytes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment