17. Definition and use of constants and structures in C #

Source: Internet
Author: User

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 " ;

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.

            Console.Write(" Please enter your name:" );
            Console.Write(" Please enter your age:" );
Xiaohong. Age=Console.ReadLine();
            Console.Write(" Please enter the gender:" );
            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 #

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.