
C# int size, new, declare array, convert it to string, double, long, short, ushort, byte and sbyte
1. C# int size
int is used to declare an integer type. It is an alias of System.Int32, with a value range of -2,147,483,648 to 2,147,483,647. It is a signed 32-bit integer, that is,it can represent positive and negative numbers.
The value range of data type is closely related to the occupied bytes. How many bytes does the int type occupy? It occupies 4 bytes, each with 8 bits, so 4 * 8 = 32 bits.
2. C# declare integer variable(new int C#)
int i = 0;
int n,count,p;//Default value 0
int n = 0,c = 1,p = 2;
int? i;//Add ?, the default value is null instead of 0
Declare int array C#:
int[] arr = { 1, 2, 3, 4, 5 };
int[] arr1 = new int[]{ 1, 2, 3, 4, 5 };
int[] arr2 = new int[5]{ 1, 2, 3, 4, 5 };
3. int is converted to other data types
A. int to string
int i = 100;
string si = i.ToString(i);
B. C# int to double
int i = 20;
double d = i;//Implicit conversion
double d = (double)i;//Forced conversion
C. C# int to long
long l = i;//Implicit conversion
long l1 = (long)i;//Forced conversion
D. C# int to short
short s = i;//Implicit conversion(error)
short s1 = (short)i;//Forced conversion
E. C# int to ushort
ushort us = i;//Implicit conversion(error)
ushort us1 = (ushort)i;//Forced conversion
F. C# int to byte
byte b = i;//Implicit conversion(error)
byte b1 = (byte)i;//Forced conversion
G. C# int to sbyte
sbyte sb = i;//Implicit conversion(error)
byte sb1 = (sbyte)i;//Forced conversion
-
Related Reading
- Javascript trim string whitespace, with removing lef
- Internet Explorer 11/10/9 did not finish installing,
- C# merge binary array(byte array)
- Convert Unicode to string C#(with string to unicode)
- Enable or disable Internet Explorer add ons and they
- How to remove unwanted add ons from Internet Explore
- C# split string with \n pay attention to the problem
- C# declare datetime variable, its range and type con
- C# efficiency comparison of multiple strings concate
- C# date format and examples, with binding and ToStri
- C# remove first or last character from string
- Difference between substr and substring in javascrip