随笔分类 - C#
常用的一些方法等
摘要:该文代码来自设计模式之惮一书。观察者模式定义: 观察者模式也叫做发布订阅模式。观察者模式中的角色: 1、被观察者 被观察者职责为管理观察者并通知观察者。 2、观察者 对接受到的消息进行处理。/// /// 被观察者 /// public abstract cl...
阅读全文
摘要:View Code XmlNode node = this.doc.SelectSingleNode(string.Format("//DXSL//Configuration[@name='{0}']", MailSettings)); XmlNode node2 = node.SelectSingleNode("Server") if (node2 != node) { Server = node2.InnerText; } XmlNodeList list = node.SelectNodes...
阅读全文
摘要:C#中使用lock和Monitor控制多线程对资源的使用,最常见的生产者和消费者问题就是多线程同步和通信的经典例子。这篇文章通过例子来了解C#多线程的同步与通信。一、关于lock和Monitorlock可以把一段代码定义为互斥段(critical section),互斥段在一个时刻内只允许一个线程进入执行,而其它线程必须等待。格式定义如下:lock(expression) statement_blockexpression代表要跟踪的对象,通常是引用。一般地,如果想保护一个类的实例,使用this;如果保护一个静态变量(如互斥代码段在一个静态方法内部),使用类名就可以了。而statement_b
阅读全文
摘要:btnCalc_Clickprivate void btnCalc_Click(object sender, EventArgs e) { double total = 0.0d; string ctypeStr = icmbCtype.SelectedItem.ToString(); css = DXSLFactory.CashFactory.CreateCashSuper(ctypeStr); double d = css.AcceptCash(double.Parse(txtMoney....
阅读全文
摘要:一、构造3个对象的集合 List<VAV_AREA> arealist = new List<VAV_AREA>(); List<VAV_CORP> corplist = new List<VAV_CORP>(); List<VAV_CITY> citylist = new List<VAV_CITY>();二、得到集合数据三、linq处理2个list to linq left join var v = from area in arealist join corp in corplist.DefaultIfEmpty()
阅读全文
摘要:查询操作符和扩展方法查询操作符是linq的一个重要设施,linq使用扩展方式定义查询操作;例如where 操作符:初始linq表达式Linq 核心实现 1 public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate) 2 { 3 foreach (T item in source) 4 { 5 if (predicate(item)) 6 { 7 ...
阅读全文
摘要:将控件的内容滚动到当前插入符号位置。 richTextBox1.ScrollToCaret();
阅读全文
摘要:(一)双击展开,收缩字表ExpandedChild1 Private Sub ExpandedChild(ByVal sender As DevExpress.XtraGrid.Views.Grid.GridView)2 '找出焦点行3 Dim VIntPage As Integer = sender.FocusedRowHandle4 If sender.GetMasterRowExpanded(VIntPage) Then5 sender.CollapseMasterRow(VIntPage)6 Else7 sender.ExpandMasterRow(VIntPage)8 End
阅读全文
摘要:View Code bool isModified = false; foreach (string key in ConfigurationManager.AppSettings) { if (key == "box") { isModified = true; } } Configuration config = ConfigurationManager.OpenExeConfiguration(Configu...
阅读全文
摘要:View Code 1 #region 枚举公用转换类 2 public class EnumDescConverter : System.ComponentModel.EnumConverter 3 { 4 protected System.Type m_MyVal; 5 public static string GetEnumDescription(Enum value) 6 { 7 FieldInfo fi = value.GetType().GetField(value.ToString(...
阅读全文
摘要:View Code 1 public ProjectInstaller() 2 { 3 InitializeComponent(); 4 this.Committed += new InstallEventHandler(ProjectInstaller_Committed); 5 } 6 7 private void ProjectInstaller_Committed(object sender, InstallEventArgs e) 8 { 9 ...
阅读全文
摘要:View Code 1 XmlDocument doc = new XmlDocument(); 2 XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "GB2312", null); 3 doc.AppendChild(dec); 4 //创建一个根节点(一级) 5 XmlElement root = doc.CreateElement("First"); 6 doc.AppendChild(root); 7 ...
阅读全文
摘要:Excel带入数据 DevExpress
阅读全文
摘要:1 using System.Net.Mail; 2 using System.Net; 3 using System.Data; 4 using System.Xml; 5 /// <summary> 6 /// EmailConfig Info 7 /// </summary> 8 public partial class EmailConfig 9 { 10 #region 11 private string _UserName; 12 private string _PS...
阅读全文
摘要:1 /// <summary> 2 /// 硬盘 3 /// </summary> 4 public class VAV_MDDFM_HD 5 { 6 private static StringBuilder strBu = new StringBuilder(); 7 8 /// <summary> 9 /// 获取硬盘空间大小10 /// </summary>11 /// <param name="Drive">指定盘符,默认为ALL</param>12 public static string G
阅读全文
摘要:View Code 1 <script type="text/javascript" language="javascript"> 2 function checkAll() { 3 4 for (var i = 0; i < document.getElementById("cblStatuteEnumTypeId").getElementsByTagName("input").length; i++) { 5 6 document.getElementById("cblStatute
阅读全文
摘要:public const int Num = 50000; //数目public const int MaxValue = 880296; //最大数public const int MinValue = 1; //最小数#region 产生随机数部分 /// <summary> /// 随机数进行排序 /// </summary> public int[] sort(int[] num) { int i, j, temp; int n = num.Le...
阅读全文
摘要:public static string statistical_data = "统计数据信息.txt"; // List<string> list = new List<string>(); // list.Add("标题=" + Title_null_num.ToString() + "RowId=" + idr["RowId"].ToString());// list.Add("内容=" + FullContent_null_num.ToString() + &qu
阅读全文

浙公网安备 33010602011771号