您的位置:首页 > 编程语言 > C#

C# Index 定义索---引具体使用

2016-06-29 13:55 429 查看
using System;

using System.Collections.Generic;

namespace TestThisIndex

{

public class Program

{

static void Main(string[] args)

{

WLJ wlj = new WLJ();

List<Patient> list = new List<Patient>();

Patient patient = new Patient();

patient.Name = "wlj";

patient.NO = "11111";

patient.Sex = "男";

list.Add(patient);

patient = new Patient();

patient.Name = "wlj1";

patient.NO = "22222";

patient.Sex = "男";

list.Add(patient);

patient = new Patient();

patient.Name = "wlj3";

patient.NO = "33333";

patient.Sex = "男";

list.Add(patient);

patient = new Patient();

patient.Name = "wlj5";

patient.NO = "4444444";

patient.Sex = "男";

list.Add(patient);

patient = new Patient();

patient.Name = "wlj6";

patient.NO = "5555555";

patient.Sex = "男";

list.Add(patient);

wlj.Plist = list;

patient = new Patient();

patient = wlj[1];

System.Console.WriteLine(patient.NO + patient.Name);

patient = new Patient();

patient = wlj["第一个"];

System.Console.WriteLine(patient.NO + patient.Name);

System.Console.Read();

}

}

public class WLJ

{

List<Patient> list = new List<Patient>();

//定义了Index为int类型

public Patient this[int index]

{

get { return list[index]; }

set { list[index] = value; }

}

//定义了Index为string类型

public Patient this[string index]

{

get

{

switch (index)

{

case "第一个":

return list[0];

case "第二个":

return list[1];

case "第三个":

return list[2];

case "第四个":

return list[3];

default:

return list[4];

}

}

set

{

switch (index)

{

case "第一个":

list[0] = value;

break;

case "第二个":

list[1] = value;

break;

case "第三个":

list[2] = value;

break;

case "第四个":

list[3] = value;

break;

default:

list[4] = value;

break;

}

}

}

public List<Patient> Plist

{

get { return list; }

set { list = value; }

}

}

#region Patient and ExamResultS

/// <summary>

/// 病人基本信息

/// </summary>

public class Patient

{

/// <summary>

/// 姓名

/// </summary>

private string _Name = null;

public string Name

{

get { return _Name; }

set { _Name = value; }

}

/// <summary>

/// 性别

/// </summary>

private string _Sex = null;

public string Sex

{

get { return _Sex; }

set { _Sex = value; }

}

/// <summary>

/// 年龄

/// </summary>

private string _Age = null;

public string Age

{

get { return _Age; }

set { _Age = value; }

}

/// <summary>

/// 样本类型

/// </summary>

private string _SampleType = null;

public string SampleType

{

get { return _SampleType; }

set { _SampleType = value; }

}

/// <summary>

/// 病区

/// </summary>

private string _Wards = null;

public string Wards

{

get { return _Wards; }

set { _Wards = value; }

}

/// <summary>

/// 床号

/// </summary>

private string _BedNumber = null;

public string BedNumber

{

get { return _BedNumber; }

set { _BedNumber = value; }

}

/// <summary>

/// 编号

/// </summary>

private string _NO = null;

public string NO

{

get { return _NO; }

set { _NO = value; }

}

/// <summary>

/// 临床诊断

/// </summary>

private string _ClinicalDiagnosis = null;

public string ClinicalDiagnosis

{

get { return _ClinicalDiagnosis; }

set { _ClinicalDiagnosis = value; }

}

/// <summary>

/// 送检医生

/// </summary>

private string _SendDoctor = null;

public string SendDoctor

{

get { return _SendDoctor; }

set { _SendDoctor = value; }

}

/// <summary>

/// 检查者

/// </summary>

private string _Proofer = null;

public string Proofer

{

get { return _Proofer; }

set { _Proofer = value; }

}

/// <summary>

/// 审核人

/// </summary>

private string _Auditor = null;

public string Auditor

{

get { return _Auditor; }

set { _Auditor = value; }

}

/// <summary>

/// 接收时间

/// </summary>

private DateTime _ReceiveTime;

public DateTime ReceiveTime

{

get { return _ReceiveTime; }

set { _ReceiveTime = value; }

}

/// <summary>

/// 报告时间

/// </summary>

private DateTime _ReportTime;

public DateTime ReportTime

{

get { return _ReportTime; }

set { _ReportTime = value; }

}

private ExamResultS _ExamResult;

public ExamResultS ExamResult

{

get

{

if (_ExamResult == null)

{

_ExamResult = new ExamResultS();

return _ExamResult;

}

else

{

return _ExamResult;

}

}

set { _ExamResult = value; }

}

}

/// <summary>

/// 检验结果

/// </summary>

public class ExamResultS

{

/// <summary>

/// 检验项目

/// </summary>

private string _ExamItem = null;

public string ExamItem

{

get { return _ExamItem; }

set { _ExamItem = value; }

}

/// <summary>

/// 结果

/// </summary>

private string _Result = null;

public string Result

{

get { return _Result; }

set { _Result = value; }

}

/// <summary>

/// 单位

/// </summary>

private string _Unit = null;

public string Unit

{

get { return _Unit; }

set { _Unit = value; }

}

/// <summary>

/// 参考值

/// </summary>

private string _ReferenceValue = null;

public string ReferenceValue

{

get { return _ReferenceValue; }

set { _ReferenceValue = value; }

}

}

#endregion

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息