特点:
1、类的成员结构:
1.1、数据成员:可以存储数据的空间;
1.2、方法成员:对每个数据写入/读取的方法。
2、类的调用:
2.1、类名字类型的变量声明:
类名字 变量名;(雷同整数数组声明:int[] a;)
2.2、变量空间开辟及堆中指向
变量名=new 类名字();(雷同整数数组指向:a=new int[3];)
2.3、写入数据
类名字.写入方法成员1(“abcdefg”);//字符串
类名字.写入方法成员2(22);//整数
2.4、读取数据
类名字.写入方法成员1();
类名字.写入方法成员2();
=================================
类的成员:数据成员、方法成员。
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace day0614
{
class Wife
{
private string name;
private string sex;
private int age;
public void SetName(string name)
{
this.name = name;
}
public void SetAge(int age)
{
this.age = age;
}
public string GetName()
{
return this.name;
}
public int GetAge()
{
return this.age;
}
}
}
类的对象声明、写入、读取。
using System;
namespace day0614
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Wife wife01;
wife01 = new Wife();
wife01.SetName("hhtt");
wife01.SetAge(22);
Console.WriteLine("姓名:{0}\t年龄:{1}" ,wife01.GetName(),wife01.GetAge());
Console.ReadLine();
}
}
}