《C#语言04-CSharp面向对象编程基础(1).pdf》由会员分享,可在线阅读,更多相关《C#语言04-CSharp面向对象编程基础(1).pdf(32页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、OO?OO?OO?(?)?(?)?(?)?C#?OO?OO?class Car int colorNumber;int doorNumber;int speed;void Brake()void SpeedUp();void SlowDown()Car myCar=new Car();myCar.SpeedUp();?B?A?:1.?2.?3.?myCar.SpeedUP(10);?C#?C#?C#?C+?C#?”?“?null?+?-?class?class Student?long id;/?char gender;/?int classID;/?class?void ChangeClas
2、s(int aClassID)/?Student student;?new?student=new Student();/?.?/?(?)student.id=200328013203194;?Student student;/?Student?student student=new Student();/?new Student()student=studentstudent Student student2=student;/?studentstudent2000000000000000000000000000000000000000000000 x01abcdef000000000000
3、00000000000000000 x01abcdef2003280132031940000000000000 x01abcdef?Student xiaoMing=new Student();Student xiaoFang=new Student();xiaoMing.gender=M;xiaoFang.gender=F;?xiaoMing.gender?M?xiaoMing?xiaoFang?(xiaoMing=xiaoFang)?false?equals?0 x01abcdef?M?xiaoMing0 x01abcdf5xiaoFang?F?Student xiaoMing=new S
4、tudent();Student xiaoFang=xiaoMing;xiaoMing.gender=M;xiaoFang.gender=F;?xiaoMing.gender?F?xiaoMing?xiaoFang?(xiaoMing=xiaoFang)?true?xiaoMing.equals(xiaoFang)?true?0 x01abcdef?F?xiaoMing0 x01abcdf5xiaoFang?int xiaoMing=100;int xiaoFang=xiaoMing;xiaoFang=200;?xiaoMing?100?(xiaoMing=xiaoFang)?false?10
5、0 xiaoMing200 xiaoFang?C#?ref?out?-?class HelloWorldstatic void change100(int x)System.Console.WriteLine(Inside method,x=+x);x=100;System.Console.WriteLine(Inside method,x=+x);static void Main(string args)int y=10;System.Console.WriteLine(Outside method,y=+y);change100(y);System.Console.WriteLine(Ou
6、tside method,y=+y);?Outside method,y=10Inside method,x=10Inside method,x=100Outside method,y=10?-?class Studentpublic int No;class HelloWorldstatic void change100(Student x)x.No=100;static void Main(string args)Student s=new Student();s.No=10;change100(s);System.Console.WriteLine(s.No=+s.No);?s.No=1
7、00?-refclass HelloWorldstatic void change100(ref int x)System.Console.WriteLine(Inside method,x=+x);x=100;System.Console.WriteLine(Inside method,x=+x);static void Main(string args)int y=10;System.Console.WriteLine(Outside method,y=+y);change100(ref y);System.Console.WriteLine(Outside method,y=+y);?O
8、utside method,y=10Inside method,x=10Inside method,x=100Outside method,y=10?-outclass HelloWorldstatic void change100(int x,out int y)y=x;static void Main(string args)int x=10,y;change100(x,out y);System.Console.WriteLine(y=+y);?out?y=10?(local)?,?automatic?temporary?stack?,?,?,?(?)?new Xxxx()?this?c
9、lass Studentlong id;char gender;int classID;void changeClass(int classID)this.classID=classID;int y=0;for(int x=0;x10;x+)y+=x;for(int x=0;x=0)id=aID;return true;else return false;public static void main(String args)?class Studentpublic int No;class Student private int No;public int GetNo()return No;
10、public void SetNo(int aNo)if(aNo 0)No=aNo;elseNo=0;class Student3private int no;public int Noget return no;setif(value 0)no=value;else no=0;class HelloWorld static void Main(string args)Student3 s=new Student3();s.No=1;?getset?get?set?static?new?public?0?1?class Studentlong id;/?char gender;/?int cl
11、assID;/?class?public Student()id=0;gender=F;classID=0;public Student(long aID,char aGender,int aClassID)id=aID;gender=aGender;classID=aClassID;?C#?C#?.Net?.net?int,string,float,DateTime?.net?80%?.NET Framework?Object.Finalize?Finalize?Finalize?Finalize?Finalize?Finalize?Close?Dispose?Close?Dispose?Dispose?Close?GC?Dispose?GC?Close?C#?IDisposable?using System;class MyFilepublic MyFile()/Open Filepublic void Close()/Close Filepublic void Dispose()Close();GC.SuppressFinalize(this);MyFile()Close();