实例1-4:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 数据结构教程第一章
{
class Stud2
{
public int num {
get; set; }//声明字段,即变量,并声明默认访问器
public string name {
get; set; }//如果需要对私有化变量进行操作,一般需要通过声明属性来对私有化变量进行读写操作
public double score {
get; set; }
public Stud2 next;
}
class 实例1_4写法一
{
public static void Output(int i,ref Stud2 head)
{
Stud2 process = head;
for (int j = 0; j < i; j++)//i表示输出的Stud2对象的数量,通过将process的next属性赋值给自己,process指向链表中的下一个对象。
{
Console.WriteLine($"num = {process.num} name = {process.name} score = {process.score}")