Chapter 1. Object-Oriented (class, Object, field, method, property, constructor)

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceObject-oriented {//Create Person class     Public classPerson {//Fields: Field        Private string_name; Private int_age; Private Char_gender; //Properties: Attributes         Public stringName {Get{return  This. _name; }//when you get the property value, call the Get method            Set{ This. _name = value; }//when assigning a value to a property, call the Set method        }         Public intAge {Get{return  This. _age;} //qualifying the Set property            Set             {                if(Value <0|| Value > -) {Value=0; }                  This. _age =value; }        }         Public CharGender {//to qualify a Get property            Get            {                if(_gender! ='male'&& _gender! ='female')                {                    return_gender ='male'; }                Else                {                    return_gender; }            }                       Set{_gender =value;} }               //Methods: Method (Behavior)         Public voidChlss () {Console.WriteLine ("My name is {0}, I am {1} years old this year, I am {2} born, I can eat and drink to sleep yo ~ ~",              This. Name, This. Age, This.        Gender); }    }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceObject-oriented {classProgram {Static voidMain (string[] args) {            //to create an object of the person classPerson Lucy =NewPerson (); Lucy.name="Lucy"; Lucy.age= - at; Lucy.gender='Spring';            LUCY.CHLSS ();        Console.ReadLine (); }    }}

Chapter 1. Object-Oriented (class, Object, field, method, property, constructor)

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.