The following are the unary operators in C# -
+ - ! ~ ++ -- (type)* & sizeof
Let us understand the sizeof operator. sizeof returns the size of the data type.
Suppose you need to find the size of int data type -
sizeof(int)
For double data type -
sizeof(double)
Let’s see the complete example to find the size of various data types -
Real-time demonstration
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
The above is the detailed content of What are unary operators in C#?. For more information, please follow other related articles on the PHP Chinese website!