三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

广州网站改版哪家好关键词林俊杰mp3在线听

广州网站改版哪家好关键词林俊杰mp3在线听 广州网站改版哪家好,关键词林俊杰mp3在线听,西安必途网站建设培训中心,南京网站设南京网站设计计C#中的成员方法#xff0c;也称成员函数#xff0c;声明在类中#xff0c;与函数的声明方法类似#xff0c;用于描述对象的行为#xff0c;受到访问修饰符的限制。成员方法的具体声明如下#xff1a;using System;namespace Leson03 {class Person() {public int age;pu…C#中的成员方法也称成员函数声明在类中与函数的声明方法类似用于描述对象的行为受到访问修饰符的限制。成员方法的具体声明如下using System; namespace Leson03 { class Person() { public int age; public string name; public Person[] friends; public void Speak(string a) { Console.WriteLine({0}说{1},name,a); } public bool IsAdult() { return age 18; } //较复杂的成员方法 public void AddFriends(Person p) { if (friends null) { friends new Person[] { p }; } else { Person[] newFriends new Person[friends.Length 1]; for (int i 0; i friends.Length; i) { newFriends[i] friends[i]; } newFriends[newFriends.Length - 1] p; friends newFriends; } } } class Program { static void Main(string[] args) { Console.WriteLine(成员方法); Person p1 new Person(); p1.name 张三; p1.age 18; p1.Speak(你好); p1.IsAdult(); Person p2 new Person(); p2.name 李四; p1.age 18; p1.AddFriends(p2); for (int i 0; i p1.friends.Length; i) { Console.WriteLine(p1.friends[i].name); } } } }需要注意的是成员方法必须在实例化对象以后由对象来调用相当于对象进行了某个行为。
← 返回列表