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