Avvenimenti
Mar 17, 11 PM - Mar 21, 11 PM
Ingħaqad mas-serje meetup biex tibni soluzzjonijiet skalabbli tal-IA bbażati fuq każijiet ta 'użu fid-dinja reali ma' żviluppaturi u esperti sħabi.
Irreġistra issaDan il-brawżer m'għadux appoġġjat.
Aġġorna għal Microsoft Edge biex tieħu vantaġġ mill-aħħar karatteristiċi, aġġornamenti tas-sigurtà, u appoġġ tekniku.
A type is an unmanaged type if it's any of the following types:
sbyte
, byte
, short
, ushort
, int
, uint
, long
, ulong
, nint
, nuint
, char
, float
, double
, decimal
, or bool
You can use the unmanaged
constraint to specify that a type parameter is a non-pointer, non-nullable unmanaged type.
A constructed struct type that contains fields of unmanaged types only is also unmanaged, as the following example shows:
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
A generic struct may be the source of both unmanaged and managed constructed types. The preceding example defines a generic struct Coords<T>
and presents the examples of unmanaged constructed types. The example of a managed type is Coords<object>
. It's managed because it has the fields of the object
type, which is managed. If you want all constructed types to be unmanaged types, use the unmanaged
constraint in the definition of a generic struct:
public struct Coords<T> where T : unmanaged
{
public T X;
public T Y;
}
For more information, see the Pointer types section of the C# language specification.
Feedback ta’ .NET
.NET huwa proġett b’sors miftuħ. Agħżel link biex tipprovdi l-feedback:
Avvenimenti
Mar 17, 11 PM - Mar 21, 11 PM
Ingħaqad mas-serje meetup biex tibni soluzzjonijiet skalabbli tal-IA bbażati fuq każijiet ta 'użu fid-dinja reali ma' żviluppaturi u esperti sħabi.
Irreġistra issa