D:\cstest>csc TaskItem.cs
D:\cstest>TaskItem
Capacity: 0
C#结构是一种值类型
24
1,任务1,1,1
1,任务1,1,4
2,任务2,1,1
2,任务2,1,2
3,任务3,1,4
4,任务4,1,1
D:\cstest>csc /d:USE_CLASS TaskItem.cs
D:\cstest>TaskItem
Capacity: 0
C#类是一种引用类型
1,任务1,1,1
1,任务1,1,1
2,任务2,1,1
2,任务2,1,2
3,任务3,1,4
4,任务4,1,1
D:\cstest>csc virtualoverride.cs
D:\cstest>virtualoverride
关键字override表示重写继承的成员
TimeZone::display 21:42:12 PST
TimeZone::display 21:42:12 PST
D:\cstest>csc /d:NOOVERRIDE virtualoverride.cs
D:\cstest>virtualoverride
关键字new或没有表示隐藏继承的成员
TimeZone::display 21:42:12 PST
Time::display 21:42:12
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
#if USE_CLASS
public class TaskItem
#else
public struct TaskItem
#endif
{
public int m_nTaskID;
public string m_strTaskName;//任务名称
public int m_nTaskLevel;//任务等级
public int m_nTaskState;//任务状态
public TaskItem(int nTaskID=0,string strTaskName="",int nTaskLevel=0,int nTaskState=0)
{
m_nTaskID=nTaskID;
m_strTaskName=strTaskName;
m_nTaskLevel=nTaskLevel;
m_nTaskState=nTaskState;
}
public static int less_second(TaskItem m1,TaskItem m2) {
if(m1.m_nTaskID!= m2.m_nTaskID)
return m1.m_nTaskID < m2.m_nTaskID?-1:1;
else
return m1.m_nTaskState < m2.m_nTaskState?-1:(m1.m_nTaskState > m2.m_nTaskState?1:0);
}
}
class Class1
{
static void Main(string[] args)
{
List
Console.WriteLine("\nCapacity: {0}", LTask.Capacity);
#if USE_CLASS
Console.WriteLine("C#类是一种引用类型");
TaskItem t=new TaskItem();
#else
Console.WriteLine("C#结构是一种值类型");
TaskItem t=new TaskItem();//或者TaskItem t;
Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(t));
#endif
t.m_nTaskID=1;
t.m_strTaskName="任务1";
t.m_nTaskLevel=1;
t.m_nTaskState=4;
LTask.Add(t);//提交
t.m_nTaskID=1;
t.m_strTaskName="任务1";
t.m_nTaskLevel=1;
t.m_nTaskState=1;
LTask.Add(t);//未接
LTask.Add(new TaskItem(2,"任务2",1,1));//未接
LTask.Add(new TaskItem(2,"任务2",1,2));//已接
LTask.Add(new TaskItem(4,"任务4",1,1));//未接
LTask.Add(new TaskItem(3,"任务3",1,4));//提交
LTask.Sort(TaskItem.less_second);
foreach(TaskItem ti in LTask)
{
Console.WriteLine("{0},{1},{2},{3}",ti.m_nTaskID,ti.m_strTaskName,ti.m_nTaskLevel,ti.m_nTaskState);
}
}
}
}
using System;
// ------------- A Time Class
class Time {
protected int hours, minutes, seconds;
public Time(int hr, int min, int sec)
{
hours = hr;
minutes = min;
seconds = sec;
}
public virtual void display()
{
Console.WriteLine("Time::display {0}:{1}:{2}",hours,minutes,seconds);
}
};
// ------------ A TimeZone Class
public enum timezone { gmt, est, cst, mst, pst }
class TimeZone :Time {
public string[] TZ={ "GMT", "EST", "CST", "MST", "PST" };
protected timezone zone;
public TimeZone(int hr, int min, int sec, timezone zn) : base(hr, min, sec)
{
zone = zn;
}
#if NOOVERRIDE
public new void display()
#else
public override void display()
#endif
{
Console.WriteLine("TimeZone::display {0}:{1}:{2} {3}",hours,minutes,seconds,TZ[(int)zone]);
}
};
public class TimeTest {
public static void Main() {
#if NOOVERRIDE
Console.WriteLine("关键字new或没有表示隐藏继承的成员");
#else
Console.WriteLine("关键字override表示重写继承的成员");
#endif
TimeZone pC=new TimeZone(21, 42, 12,timezone.pst);
pC.display();
Time pB = pC;
pB.display();
}
}