C # object-oriented programming for the gentle and newest Learning Series-class data member (3)

Source: Internet
Author: User

Class Data Structure

A class is a data structure that includes data members, function members, and nested types for encapsulation.

Data Member contained in the class

Constructor, destructor, constant, field, attribute, method, event, Delegate, class, structure, interface, Indexer

Data members can be static members, that is, they are related to the entire class or instance members, that is, they are related to objects.

Fields are class-related variables. They are declared in the same way as declared variables. fields are declared in the class, and variables are declared in the main function and method.

Instance

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

namespace _ 3_classmember
{< br> class Program
{< br> static void main (string [] ARGs)
{< br> Student = new student ();
console. writeline ("Name: {0}", student. _ name);
console. writeline ("Age: {0}", student. _ age);
// we can see that the access constant must be accessed by the student class. The constant belongs to the class member, and the field belongs to the member of the instantiated object.
console. writeline ("Gender: {0}", student. _ sex);
console. readkey ();
}< BR >}

Class student
{
// Declare Fields
Public String _ name = "James ";
Public int _ age = 25;
// Declare a constant
Public const string _ sex = "male ";
}
}

Running Effect

 

 

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.