微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C# 中什么是一元运算符?

C# 中什么是一元运算符?

以下是 C# 中的一元运算符 -

+ - ! ~ ++ -- (type)* & sizeof

让我们了解一下 sizeof 运算符。 sizeof 返回数据类型的大小。

假设您需要查找 int 数据类型的大小 -

sizeof(int)

对于双数据类型 -

sizeof(double)

让我们看看完整的示例来查找各种数据类型的大小 -

示例

实时演示

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         Console.WriteLine("The size of int is {0}", sizeof(int));
         Console.WriteLine("The size of int is {0}", sizeof(char));
         Console.WriteLine("The size of short is {0}", sizeof(short));
         Console.WriteLine("The size of long is {0}", sizeof(long));
         Console.WriteLine("The size of double is {0}", sizeof(double));

         Console.ReadLine();
      }
   }
}

输出

The size of int is 4
The size of int is 2
The size of short is 2
The size of long is 8
The size of double is 8

以上就是C# 中什么是一元运算符?的详细内容,更多请关注编程之家其它相关文章

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐