C # sizeof operator

Source: Internet
Author: User

One, C # sizeof operator

The sizeof operator is used to get the number of bytes of a value type.

Ii. examples

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Test
{
Class Program
{
static void Main (string[] args)
{
C # sizeof operator-www.baike369.com
Console.WriteLine (the number of bytes SByte is: "+ sizeof (sbyte) +" bytes ");
Console.WriteLine ("Byte number of bytes is:" + sizeof (Byte) + "byte");
Console.WriteLine ("Short" bytes are: "+ sizeof (short) +" bytes ");
Console.WriteLine (the number of bytes UShort is: "+ sizeof (ushort) +" bytes ");
Console.WriteLine (the number of bytes in int is: "+ sizeof (int) +" byte ");
Console.WriteLine ("The number of bytes in float is:" + sizeof (float) + "byte");
Console.WriteLine ("Number of bytes of double is:" + sizeof (double) + "byte");
Console.WriteLine (the number of bytes in char is: "+ sizeof (char) +" byte ");
Console.WriteLine ("BOOL byte number is:" + sizeof (BOOL) + "byte");
Console.ReadLine ();
}
}
}

Operation Result:

The number of bytes SByte is: 1 bytes
The byte count of byte is: 1 bytes
The number of bytes in short is: 2 bytes
The number of bytes UShort is: 2 bytes
The number of bytes in int is: 4 bytes
The number of bytes in float is: 4 bytes
The number of bytes in double is: 8 bytes
The number of bytes in char is: 2 bytes
The number of bytes in bool is: 1 bytes

C # sizeof operator

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.