首页 > 代码库 > Variables
Variables
// C# syntax for declaring variables merely specifi es the type and variable name:
// <type> <name>;
//
//
// Simple Types
//
// Integer Types
// TYPE ALIAS FOR ALLOWED VALUE
//
// sbyte System.SByte Integer between −128 and 127
// byte System.Byte Integer between 0 and 255
// short System.Int16 Integer between −32768 and 32767
// ushort System.UInt16 Integer between 0 and 65535
// int System.Int32 Integer between −2147483648 and 2147483647
// uint System.UInt32 Integer between 0 and 4294967295
// long System.Int64 Integer between −9223372036854775808 and 9223372036854775807
// ulong System.UInt64 Integer between 0 and 18446744073709551615
//
//
// -The u characters before some variable names are shorthand for unsigned, meaning that you can’t store
// -negative numbers in variables of those types
//
//
//
// Floating-point Types
// -float, double, decimal
//
//
// Text and Boolean Types
//
// TYPE ALIAS FOR ALLOWED VALUES
// char System.Char Single Unicode character, stored as an integer between 0 and 65535
// bool System.Boolean Boolean value, true or false
// string System.String A sequence of characters
Variable Naming
// -The basic variable naming rules are as follows:
// -1.The first character of a variable name must be either a letter, an underscore character(_), or the at
// - symbol (@)
//
// -2.Subsequent characters may be letters, underscore characters, or numbers.
//
// aa, a_, a2,
// _a, __, _2,
// @a, @_, @2,
//
//
//
// -Remember that C# is case sensitive
//
// -Naming Conventions
// -For your simple variables, stick to camelCase
// -use PascalCase for certain, more advanced naming
Variable Declaration and Assignment
// -declare variables simply using their type and name:
// ing age;
// age = 25;
//
// -NOTE: Remember that variables must be initialized before you use them. The
// - preceding assignment could be used as an initialization
//
// -declare multiple variables of the same type at the same time by separating their names with commas after the type
// int xSize, ySize;
//
// -assigning values to variables when you declare them
// int age = 25;
// int xSize = 4, ySize = 5;
//
//
// int xSize, ySize = 5;
// -results in only ySize being initialized — xSize is just declared, and it still needs to be initialized before it’s used.
Variables