美文网首页
Operator : sizeof、typeof、nameof

Operator : sizeof、typeof、nameof

作者: 津涵 | 来源:发表于2019-02-13 09:43 被阅读0次

    sizeof操作符

    (1)值类型的byte sizes
    You can determine the size (in bytes) required on the stack by a value type using the sizeof operator.
    coding:
    Console.WriteLine(sizeof(int));
    //This displays the number 4 because an int is 4 bytes long.
    (2)只有值变量的struct
    You can also use the sizeof operator with structs if the struct contains only value types.
    coding:
    public struct Point
    {
    public Point(int x, int y)
    {
    X = x;
    Y = y;
    }
    public int X { get; }
    public int Y { get; }
    }
    (3)不建议用在类class中,会导致不安全代码
    By default, unsafe code is not allowed. You need to specify the AllowUnsafeBlocks in the csproj project file.

    typeof操作符

    (1)typeof(string) returns a Type object representing the System.String type

    nameof操作符

    (1)This operator accepts a symbol, property, or method and returns its name.

    相关文章

      网友评论

          本文标题:Operator : sizeof、typeof、nameof

          本文链接:https://www.haomeiwen.com/subject/hgrreqtx.html