随笔分类 -  C#相关

摘要://Get Registry item value of key, item name=name public string GetValue(RegistryKey rootKey, string path, string itemName) { if (string.IsNullOrEmpty(itemName) || rootKey == null || string.IsNullOrEmpty(path)) return null; try { ... 阅读全文
posted @ 2014-02-13 09:08 quietwalk 阅读(318) 评论(0) 推荐(0) 编辑
摘要:正确写法1 bool bTemplatecontent2 = strtemplateContentInDB.Equals(strTemplateContentInDesignPanel, StringComparison.Ordinal); bTemplatecontent2 = true;正确写法2bool bEqual = String.Equals(strtemplateContentInDB, strTemplateContentInDesignPanel, StringComparison.Ordinal);bEqual = true; 阅读全文
posted @ 2014-01-23 20:41 quietwalk 阅读(1102) 评论(0) 推荐(0) 编辑
摘要:• 浮点数不能直接用算数操作符比较大小,如:==, !=, >=, <= operators and Equals 方法,要用以下形式:Math.Abs(x - y) < Single.Epsilon;Single.Epsilon 字段表示大于零的最小正 Single 值。此字段为常数。 Double.Epsilon 字段 表示大于零的最小正 Double 值。此字段为常数。 阅读全文
posted @ 2014-01-23 20:40 quietwalk 阅读(2070) 评论(0) 推荐(0) 编辑
摘要:bool Double.TryParse(string, out double)Int32.TryParse string strInt="37"; int iOut; if (Int32.TryParse(strInt, out iOut)) { int iRet = iOut; }double.TryParse string strNumber = "123"; double dRet; if (doub... 阅读全文
posted @ 2014-01-23 20:38 quietwalk 阅读(1379) 评论(0) 推荐(0) 编辑
摘要:如果用foreach,会造成被遍历的集合更改后带来异常问题。方法一:用for循环可有效的解决这个问题。for(int i=0;i newlists=new List();foreach(T t in List){ lists.add(t);}foreach(T t in newlists){ List.Remove(t);} 阅读全文
posted @ 2014-01-23 20:37 quietwalk 阅读(1942) 评论(0) 推荐(0) 编辑
摘要:out: 也是通过引用传值,但不需初始化ref 参数 :迫使值参数通过引用传送对于ref传参,只要记住一点:对于值类型来说传的是值的地址,对于引用类型来说传的是地址的地址。对于引用类型,同样记住一点:引用类型本身的地址是一个值类型。直观的理解:引用类型对象本身不改变,只改变对象的属性时,我们在操作同一个对象;如果连对象本身都可能会改变,就用ref传引用类型的对象吧! 阅读全文
posted @ 2014-01-23 20:36 quietwalk 阅读(142) 评论(0) 推荐(0) 编辑
摘要:C#的一个新特征是也可以给类编写无参数的静态构造函数。这种构造函数只执行一次,而前面的构造函数是实例构造函数,只要创建类的对象,就会执行它。 1.编写静态构造函数的一个原因是,类有一些静态字段或属性,需要在第1次使用类之前,从外部源中初始化这些静态字段和属性。2..Net 运行库没有确保什么时候执行静态构造函数,所以不应把要求在某个特定时刻(例如,加载程序集时)执行的代码放在静态构造函数中。也不能预计不同类的静态构造函数按照什么顺序执行。但是,可以确保静态构造函数至多运行一次,即在代码引用类之前调用它。在唧中,通常在第一次调用类的任何成员之前执行静态构造函数。3.静态构造函数没有访问修饰符,其 阅读全文
posted @ 2014-01-23 20:34 quietwalk 阅读(1615) 评论(0) 推荐(0) 编辑
摘要://WCF service: string servicePath = System.Web.Hosting.HostingEnvironment.MapPath("~"); //F:\WorkSpace\EHR\src\vs2010\EHR\EHR\bin\Debug\ string strBaseDirectory = System.AppDomain.CurrentDomain.BaseDirectory; //F:\WorkSpace\EHR\src\vs2010\EHR\EHR\bin\Debug\EHR.vshost... 阅读全文
posted @ 2014-01-23 20:33 quietwalk 阅读(2522) 评论(0) 推荐(0) 编辑
摘要:1.序列化 public static byte[] SerializeObject(object obj) { if (obj == null) return null; MemoryStream ms = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(ms, obj); ms.Position = 0; ... 阅读全文
posted @ 2014-01-23 20:32 quietwalk 阅读(4023) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Runtime.Serialization.Formatters.Binary;using System.Security.Cryptography;using System.Text;//xlding, 2013/07/25namespace Gemr.Utils{ public class CommonAlgorithms { #region Sort public ... 阅读全文
posted @ 2014-01-23 20:29 quietwalk 阅读(2180) 评论(0) 推荐(0) 编辑
摘要:ObservableCollection oc = new ObservableCollection();ls.ForEach(x => oc.Add(x)); 阅读全文
posted @ 2014-01-23 20:28 quietwalk 阅读(263) 评论(0) 推荐(0) 编辑
摘要:private void Test() { List lsA = new List(); lsA.Add("A"); lsA.Add("B"); lsA.Add("C"); lsA.Add("D"); List lsB = new List(); lsB.Add("C"); lsB.Add("D"); lsB.Add("E"); lsB.Add("F"); ... 阅读全文
posted @ 2014-01-23 20:25 quietwalk 阅读(470) 评论(0) 推荐(0) 编辑
摘要:public List GetViews() where V : View { var views = from item in dockLayoutManager1.GetItems() where item is LayoutPanel && ((LayoutPanel)item).Content.GetType() == typeof(V) select ((LayoutPanel)item).Content as V; return v... 阅读全文
posted @ 2014-01-23 20:24 quietwalk 阅读(102) 评论(0) 推荐(0) 编辑
摘要:Dictionary 的几种遍历方法Dictionarydic = newDictionary();方法1foreach (var item in dic){Console.WriteLine(dic.Key + dic.Value);}方法2//KeyValuePairforeach (KeyValuePair kv in dic){Console.WriteLine(kv.Key + kv.Value);}方法3//通过键的集合取foreach (string key indic.Keys){Console.WriteLine(key + list[key]);} 阅读全文
posted @ 2014-01-23 20:23 quietwalk 阅读(317) 评论(0) 推荐(0) 编辑
摘要:public static StringBuilder GetProperties(object obj) { if (obj == null) return null; Type t = obj.GetType(); PropertyInfo[] propertyInfo = t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); StringBuilder sb = ne... 阅读全文
posted @ 2014-01-23 20:22 quietwalk 阅读(172) 评论(0) 推荐(0) 编辑
摘要:public static string GetSHA1Method(string strSource) { string strResult = ""; //Create System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create(); byte[] bytResult = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strSour... 阅读全文
posted @ 2014-01-23 12:44 quietwalk 阅读(1893) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.Text;using System.Net.Mail;using System.Net;using System.IO;namespace Haitai{ public class EmailClient { public EmailClient(string host, int port, bool enableSsl, string username, string password) { _host = hos... 阅读全文
posted @ 2014-01-23 12:12 quietwalk 阅读(252) 评论(0) 推荐(0) 编辑
摘要:private DispatcherTimer _timer; private void SetTimeElaspInStatusBar() { try { _timer = new DispatcherTimer(); _timer.Tick += (sender, e) => { DateTime dtNow = DateTime.Now; TimeSpan interval = dtNow - _enterSystemTime; this.barElapsedTime.Content = null; #region TimeZoneInfo currentTimeZone = Ti 阅读全文
posted @ 2014-01-23 12:06 quietwalk 阅读(1213) 评论(0) 推荐(0) 编辑
摘要:http://www.cnblogs.com/multiplesoftware/archive/2011/09/27/2192710.html当对字符串进行操作时,我们经常要删除或者是替换一部分子字符串。 Remove() 和 Replace() 两个函数在这种情况就派上用场了。Remove() – 删除一部分子字符串我们都知道 substring 可以返回字符串的一部分。 当我们想保留字符串中的一部分substring丢弃其它部分时,就可以使用substring,当我们想删除字符串的一部分并保留其它部分时,就使用Remove。Remove 有两种形式:Remove(int startInde 阅读全文
posted @ 2013-08-22 09:49 quietwalk 阅读(472) 评论(0) 推荐(0) 编辑
摘要:http://www.cnblogs.com/iloveWater/articles/2209769.html1.在每个文件的头部必须包括以下注释:(更多文档注释内容查看>>)/*---------------------------------------------------------------- // Copyright (C) 2010 南昌大学家园网版权所有。 // // 文件名: // 文件功能描述: // // // 创建人:(姓名,联系方... 阅读全文
posted @ 2012-12-24 14:52 quietwalk 阅读(334) 评论(0) 推荐(0) 编辑