1.0 类、对象和方法
因为自己java出身,就不在这里讲什么类和对象、方法、函数、构造函数了。直接上语法糖。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestDemo
{
/// <summary>
/// 类:学员类
/// </summary>
class Student
{
//字段:学员id
private int studentNo;
//字段:学生姓名
private string studentName = string.Empty;
//属性:学号
public int StudentNo
{
get { return studentNo; }
set { studentNo = value; }
}
//属性:学生姓名
public string StudentName
{
get { return studentName; }
set { studentName = value; }
}
//方法:获取学员信息
public string GetStudent()
{
string info = string.Format("姓名:{0};学号:{1}。", studentName, studentNo);
return info;
}
static void Main(string[] args)
{
//创建对象
Student objStu = new Student();
//给对象属性赋值
objStu.StudentNo = 10001;
objStu.StudentName = "小明";
//调用对象的方法
string info= objStu.GetStudent();
Console.WriteLine(info);
Console.ReadLine();
}
}
}



2.0 构造方法(构造函数)


3.0 对象初始化器
本小节内容从.NET3.0以上版本才可使用。

4.0 垃圾回收机制(GC)
和java的一模一样。.NET虚拟机特有机制,自动运行,并检查对象的状态,发现对象不在引用时,会将其释放所占你的空间(销毁)。
5.0 对象的数据类型

6.0 ref和out关键字


Operation方法中,out约束的返回值会跟随原有的返回值一起返回。
END
网友评论