Console Format
using System;
class hello
...{
static void Main()
...{
string strStr,strF="{0:#,###;#.##;0.0##}",strTmp; float f;
do
...{
Console.Write(" Input Number -1 Exit: ");
f = float.Parse(Console.ReadLine());
if (f == -1) goto MM;
do...{
Console.Write(" Input Format or / Enter Number: ");
strTmp= Console.ReadLine();
if (strTmp != "/") strF = strTmp;
strStr = string.Format(strF, f);
Console.WriteLine("Format {0} {1}", strF,strStr);
if (strTmp == "/") break;
} while (true);
} while (true);
MM:Console.WriteLine("Now:{0:Y} {0:T}",DateTime.Now);
}
}
using System;
class hello//struct結構和類的另外一點差異在於,結構並不一定需要利用new關鍵字創建對象
...{ //結構並不支持繼承的機制,當然也不能使用繼承關系的修飾符abstract,virtual以及protected
static void Main()//結構不需要額外地配置內存又可以創建構造函數,常數,字段,方法,屬性,索引器,運算符等成員
...{
intIm = 2;
string sName; string strN = "";
System.Console.Write("========================== Input Name:");
sName=System.Console.ReadLine();
if (sName.Contains("."))...{ strN="Contains ''.'' in"; return; }
strN = strN + "."; intIm+=2;
System.Console.WriteLine("Your Name is: {0} {1}",sName,strN);
CreatClass myClsMsg=new CreatClass(88);
//Console.WriteLine("{0} {1}", myClsMsg.intI, myClsMsg.accHelloMessage);//讀屬性
myClsMsg.accHelloMessage="這是測試的字符串.";
inherit myClsInh = new inherit();
Console.WriteLine("========顯示信息==========");
myClsMsg.ShowMessage();
Console.WriteLine("========顯示信息==========");
myClsInh.ShowMessage();
Console.ReadLine();
}
static public int intIm;
}
public class CreatClass
...{ public int intI;
string helloMessage="類原始信息";
public void ShowMessage()
...{int intI = 8;
Console.WriteLine(helloMessage);
Console.WriteLine("->類內: this.intI={0}", this.intI);
Console.WriteLine("->hell:hello.intIm={0}", hello.intIm);
//Console.WriteLine("->hell: intIm={0}", intIm);
Console.WriteLine("->默認:intI= {0}, {1}", intI, int.MaxValue);
}
public string accHelloMessage
...{ get...{return helloMessage;}
set...{helloMessage=value;}
}
public CreatClass(int sVal)
...{
this.intI = sVal;
Console.WriteLine("->初始化:intI={0}", this.intI);
}
public CreatClass()
...{
this.intI = -1;
Console.WriteLine("=>初始化:intI={0}", this.intI);
}
}
class inherit : CreatClass//construct
...{
public inherit(): base()
...{
this.intI = -2;
Console.WriteLine("=|>繼承類:intI={0}", this.intI);
}
~inherit()
...{
Console.WriteLine("繼承類結束:intI={0}", this.intI);
}
}