随笔分类 - C#
摘要:二进制在C#中无法直接表示,我们一般用0和1的字符串来表示一个数的二进制形式。比如5的二进制为“101”。下面介绍C#里面用于进制转换方法。 十进制转换为二进制(int-->string) System.Convert.ToString(d, 2);// d为int类型 以5为例,输出为101 十六
阅读全文
摘要:// RightReciver = System.Text.Encoding.ASCII.GetString(bt);//接收中文出现会出现问号乱码的,改成UTF8就ok了 RightReciver = System.Text.Encoding.UTF8.GetString(bt); using S
阅读全文
摘要:首先连接超时分为三种,TCP Connection to SQL Server -> SqlConnection.Open -> SqlCommand.Execute先说第二种超时,sqlcon打开,我们不能直接设置connectiontimeout,只能在连接字符串中设置:Data Source=
阅读全文
摘要:c#winform不要通过文件右键属性去复制文件路径,会复制到隐藏的字符,打印路径会看见问号
阅读全文
摘要:c#序列化json文件为字符串-更改json对象内容 public static dynamic Serializ(string send) { try { string path = Application.StartupPath + $@"\{send}"; var file = new Fil
阅读全文
摘要:HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;//创建请求对象 request.Timeout = 2000; request.Method = "POST";//请求方式 request.ContentType
阅读全文
摘要:c#winform大括号自动对齐快捷键 CTRL +K+D这是vs中格式化代码的快捷键
阅读全文
摘要:引用: OFFICE.DLL Microsoft.Office.Interop.Excel.dll public static void ToExcel(ListView LView, string strTitle) { try { Microsoft.Office.Interop.Excel.A
阅读全文
摘要://判断是否为数字型字符串 System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$"); //判断是否为数字型字符串 System.Text.RegularExpressi
阅读全文
摘要:/声明一个XmlDocument类对象,并将文件加载的对象中 XmlDocument doc = new XmlDocument(); string path1 = @".\aa1.xml"; //程序运行的当前目录的aa1.xml文件 string path2 = @"..\aa1.xml"; /
阅读全文
摘要:FormClosing与FormClosed事件 都是关闭窗体触发的事件, 区别 FormClosing事件 是在 关闭窗体时发生,用户可以在该事件中 取消关闭,窗体仍然保持打开状态。因此可以在该事件中提示一些状态信息,询问用户是否关闭窗口。 FormClosed事件 是在 关闭窗体后发生,可以在该
阅读全文
摘要:1.拖入控件notifyIcon1到窗口 2.拖入ContextMenuStrip到窗口 3.选中notifyIcon1右键属性,右侧属性窗口栏找到ContextMenuStrip,选择contextMenuStrip1 4.选择ContextMenuStrip,添加菜单选项 右键图标: Form1
阅读全文
摘要:C#winform picturebox形状变成圆形_重绘-默认是长方形 private void Form1_Load(object sender, EventArgs e) { //GraphicsPath gp = new GraphicsPath(); //gp.AddEllipse(thi
阅读全文
摘要:C#没有map这个类,相似功能的是Dictionary。 Dictionary<String, String> dd = new Dictionary<String, String>();dd.Add("a","aaa");dd["b"]="bbb"; Console.WriteLine(dd["a
阅读全文
摘要:c#数组用linq语句查询奇偶数并排序 使用LINQ和Lambda表达式根据特定条件来查询数组 int[] names = { 8,9,22,23,7,2}; int[] evens = names.Where(p1 => p1 % 2 == 0).OrderByDescending(p1=>p1)
阅读全文
摘要:1、接口类似于类,但接口的成员都没有执行方式,它只是方法、属性、事件和索引符的组合而已,并且也只能包含这四种成员;、、类除了这四种成员之外还可以别的成员(如字段)。2、不能实例化一个接口,接口只包括成员的签名;、、而类可以实例化(abstract抽象类除外)。3、接口没有构造函数,、、类有构造函数。
阅读全文
摘要:private void ScanAllPLCStatus() { foreach (OpcUtil.PLC_Sensor_Enum e in Enum.GetValues(typeof(OpcUtil.PLC_Sensor_Enum))) { Console.WriteLine(e.ToStrin
阅读全文
摘要:Visual Assist X for vs2005 http://www.rsdown.cn/down/165522.html#download http://d1.xszdll.cn:8001/rsdown/Visual%20Assist%20X%20for%20vs2005.rar
阅读全文
摘要:c#信号量实现线程挂起,暂停,继续,停止操作 using System; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace testManualResetEvent
阅读全文
摘要:string[] aa_tt = new string[20]; string[] aa_tt2 = new string[20]; Array.Clear(aa_tt,0,aa_tt.Length); //数组每个元素置零 Array.Copy(aa_tt,aa_tt2,aa_tt.Length)
阅读全文