using system;using system.collections.generic;using system.linq;using system.text; Namespace _4. Constant { class program { static void main (String[] args) { // Integral type Constants uint myUint = 456; console.writeline ("myUint = {0}", myuint); long mylong = 79854456l; console.writeline (" Mylong = {0} ", mylong); // floating-point constants float myFloat = 3.14F; console.writeline ("myfloat = {0}", myfloat); double myDouble = 3.14E55; console.writeline ("mydouble = {0}", myDouble); // character-type constants console.writeline ("Backslash: " + ' \ \ '); console.writeline ("single quote: " + "\");   Console.WriteLine ("Double quote: " + "'); console.writeline ("Warning sound: " + ' \a '); console.writeline ("Backspace: " + ' \b '); console.writeline ("Page break: " + ' \f '); console.writeline ("line break: " + ' \ n '); console.writeline ("carriage return: " + ' \ R '); console.writeline ("Horizontal tab: " + ' \ t '); console.writeline ("Vertical tab: " + ' \v '); Console.WriteLine ("\\u0061: " + ' \u0061 '); // string Constants string myString1 = "Hello world"; console.writeline ("myString1: " + &NBSP;MYSTRING1); // Ordinary string constants cannot be allocated on multiple lines string mystring2 = @ "hello world "; console.writeline ("mystring2: " + myString2); // if the literal specified string contains "need to be escaped to avoid ending the string." string path1 = "c:\\ Windows\\mydir "; console.writeline (" path1: " + path1); string path2 = @ "C:\Windows\MyDir"; console.writeline ("path2: " + path2); The // string is a reference type and can be assigned null. // Boolean Constants bool myBool = true; consOle. WriteLine ("mybool: {0}", mybool); // Defining Constants const float PI = 3.14F; console.writeline ("PI: " + PI); // PI = 3.1415926F; // console.writeline ("PI: " &NBSP;+&NBSP;PI) The value of the; // constant cannot be modified after it is assigned. console.readkey (); } }}/** * the basic concepts * 1. constants of constants are fixed values that do not change during program execution. * 2. constants can be used as regular variables, except that their values cannot be modified after they are defined. * * Classification of constants * (1) integer constants * integer constants can be expressed in decimal, octal, and 16 binary formats. * hexadecimal representation: prefixed with 0x and 0X. * octal representation: prefixed with 0. * decimal representation: no prefix. * * integer constants can also have suffixes, and u represents unsigned,l for long. * int,uint,long,ulong can be no suffix. * uint,ulong is indicated by the suffix U. * long,ulong is indicated by the suffix L. * ulong can be represented by the suffix ul,ul,ul,ul,lu,lu,lu,lu. * * (2) floating-point constants * floating-point constants consist of integral parts, decimal points, fractional parts, and exponential portions. * floating-point constants are represented in both decimal and exponential form. * when you use decimal notation, you must include a decimal point, an exponent, or both. * When you use an exponential form, you must include an integer part, a fractional part, or both. * signed indices are expressed in E and E. * * (3) character constants * character constants are enclosed in single quotes and can be stored in a simple character-type variable. The * character constants are divided into: ordinary characters, escape sequences, and universal characters. * escape character sequence: * \\ backslash \ ' single quote \a Warning &NBSP;*&NBSP; \ " nickname \b backspace * \f Page break \n line feed \r carriage return * \t horizontal tab Stop \v vertical tab stop * \uxxxx 4 bit hexadecimal value * * (4) string constant * 1. normal string * 2. verbatim specifying string, using the @ symbol * * Define constants * Use the Const keyword to define constants. * Defining Syntax: * const <data_type> <constant_name> = < value>; * * parameter Parsing: * <data_type>: valid C # data types * < constant_name>: constant name * <value>: value */
This article is from the "MK IT Life" blog, so be sure to keep this source http://vikxiao.blog.51cto.com/9189404/1585718
Iv. Constants