In C # , constants refer to a fixed amount. This constant can be a numeric, text, or Boolean type.
For example:
// Define constants
Const intage= -;
Const stringname=" Little Red " ;
Const BOOLflag=true;
// try to modify the constants, but this is not feasible.
age= -;
name=" Xiao Lan " ;
flag=false;
Explanation: The definition of a constant is to add a keyword to the left on the basis of defining the variable Const.
In C # , the definition of a struct is actually a custom data type. What to say is that the custom data types within the language are very similar.
The structure is defined in the following general:
Public struct -Custom data types
{
Public type variable name ;
Public type variable name ;
}
For example, define a type: Book.
public struct Type_book
{
public string title;
public string Price;
public string author;
}
Define a type of: student.
public struct type_student
{
public string name;
public string age;
public string gender;
public string Great;
}
Example: Define a type of: person. and use them.
Public struct Type_person
{
Public string name;
Public string Age;
Public string Gender;
}
use the structure type of this definition.
Type_personXiaohong;
Console.Write(" Please enter your name:" );
Xiaohong.name=Console.ReadLine();
Console.Write(" Please enter your age:" );
Xiaohong. Age=Console.ReadLine();
Console.Write(" Please enter the gender:" );
Xiaohong.Gender=Console.ReadLine();
Console.WriteLine(" Name:{0}; Age: {1}; Gender: {2} " , Xiaohong.name, Xiaohong. Age, Xiaohong.Gender);
This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1970429
17. Definition and use of constants and structures in C #