用于测试错误的抛出错误:
throw new System.Exception("这是自定义错误");
当前用户:
[CheckinLogin]
stringuser=CurrentUser;
自定义值为下拉框赋值:
var query = newDictionary<int, string> {
{ 1, "参数1" },
{ 2, "参数2" },
{ 3, "参数3" }};
日期的12小时制与24小时制:
12: DateTime.Now.ToString("hh:mm:ss")
24: DateTime.Now.ToString("HH:mm:ss")
定时执行程序(使用Timer):
Publicvoid Func1()
{
System.Timers.TimerTimer1=new System.Timers.Timer();
Timer1.Enabled = true; //是否启用
Timer1.Interval = 1000; //毫秒数
Timer1.Elapsed += newElapseEventHandler(Timer1_Elapsed);
Timer1.Start();
}
Public voidTimer1_Elapsed(object s,System.Timers.ElapsedEventArgs e))
{
………………..
}
将字符串放入文件:
StreamWriter sw =new StreamWriter("C:\\a.txt", true); //创建文件
sw.WriteLine("txtxtxtxtxtxtxtxtxtxtxt"); //将字符串写入
sw.Flush(); //将流放入文件
sw.Close(); //结束写入
判断数组中包含某元素:
bool IsTrue =Strs.Contains("1");
字符串反序列化为XML:
String str = XmlUtil.Deserialize(typeof(实体对象), 字符串);
XML序列化为字符串:
string replyStr = XmlUtil.Serializer(typeof(实体对象), 对象名);
对象反序列化为Json:
String aa= new JsonSerializer().Serialize(对象名); //引用using System.Web.Script.Serialization;
Json序列化为对象:
实体对象 [对象名]=new JsonSerializer().Deserialize<SetMedCardInfoInt>(input); //引用using System.Web.Script.Serialization;