美文网首页
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

    sizeof操作符 (1)值类型的byte sizesYou can determine the size (in...

  • sizeof 和 strlen

    sizeof 定义 sizeof是C/C++中的一个操作符(operator),简单的说其作用就是返回一个对象或者...

  • 2019-08-26 新写法 nameof

    string 你好 = nameof(你好); DataTable dataTable = new D...

  • sizeof()的用法

    1. 定义 sizeof 是一个操作符 operator,不是一个函数,其作用是返回一个对象或类型所占的内存字节数...

  • C++ sizeof的用法

    sizeof是一个操作符(operator)作用是返回一个对象或类型所占的内存字节数。返回值类型为size_t,可...

  • 1209_已添加了具有相同键的项

    原因:nameof(HL7RMYYZyBqyz) 不是 本类对象。字典集。

  • 刷题No5 sizeof

    定义:sizeof 是一个操作符(operator),其作用是返回一个对象或类型所占的内存字节数。其返回值类型为s...

  • 布尔

    sizeof(BOOL) = 1sizeof(bool) = 1sizeof(Boolean) = 1

  • 【C语言】3.sizeof

    1.sizeof sizeof并不是函数,而是运算符。可以用sizeof计算有多少字节。通常用sizeof(常量/...

  • C 基本数据类型内存

    sizeof long int=4; //这与int一样 sizeof shor int=2; sizeof do...

网友评论

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

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