
C#
fwsylin
这个作者很懒,什么都没留下…
展开
-
PLINQ
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace PLINQ_AsParallel{ public class Person { public int ID { get; set; } public stri.原创 2021-12-20 14:28:20 · 273 阅读 · 0 评论 -
定时器回调
在System.Threading命名空间中存在Timer类与对应的TimerCallback委托,它可以在后台线程中执行一些长期的定时操作,使主线程不受干扰。Timer类中最常用的构造函数为 public Timer( timerCallback , object , int , int )timerCallback委托可以绑定执行方法,执行方法必须返回void,它可以是无参数方法,也可以带一个object参数的方法。第二个参数是为 timerCallback 委托输入的参数对象。第三个参数是开始原创 2021-12-20 14:27:49 · 823 阅读 · 0 评论 -
任务并行案例
并行简单案例using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace Parallel_Test{ [Serializable] public class Person { public int ID {.原创 2021-12-20 14:07:00 · 455 阅读 · 0 评论 -
Linq for XML
using System;using System.Data.Linq;using System.Xml.Linq;using System.Linq; //select needusing System.Collections;namespace ConsoleApplication1{ class Program { static void Main() { #region linq_1 //.原创 2021-12-14 12:22:37 · 395 阅读 · 0 评论 -
SOAP for WebService
GetToolInfor.xml<?xml version="1.0" encoding="utf-8" ?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body原创 2021-12-14 12:02:32 · 360 阅读 · 0 评论 -
Windows启动时自动运行程序
打开启动文件夹 仅对当前用户生效:C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 对所有用户生效:C:\ProgramData\Microsoft\Windows\Start Menu\Program\Startup 新建运行程序的bat程序的xxx.txt文件,写入启动程序后,将文件名改为xxx.bat,start /d "C:\Program Files\TightVNC" t原创 2021-12-13 16:19:24 · 391 阅读 · 0 评论 -
带List的类的序列化实例
Product类using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Xml;using System.Xml.Serialization;namespace XmlSerialization{ //[XmlRoot(ElementName = "Product")] public class原创 2021-12-13 15:40:48 · 428 阅读 · 0 评论 -
C# 文件夹操作
C# 文件夹操作原创 2021-12-01 12:12:59 · 176 阅读 · 0 评论 -
C# WPF for TaskDialog
添加引用 using System.Runtime.InteropServices;导入dll [DllImport("comctl32.dll", PreserveSig = false, CharSet = CharSet.Unicode)] static extern TaskDialogResult TaskDialog(IntPtr hwndParent, IntPtr hInstance, string title, ...原创 2021-11-03 15:10:50 · 310 阅读 · 0 评论 -
WPF如何使用log4net
一 安装配置log4net1. 下载log4net选择生成的项目,右键,再选择‘Manage NuGet Packages’2. 搜索log4net,并安装1. 选择生成的项目,右键添加‘App.config’4. 写配置文件在上一步生成的App.config中写log4net的配置文件<configurattion> <configSections> <section name="log4net" type="log4net.Config.Log4Ne原创 2021-09-07 15:25:47 · 4827 阅读 · 1 评论 -
如何在自建线程设置中Brush
用静态Brushes值定义Brush brush = Brushes.LightBlue; //Brushes内的值为静态值,可以跨线程使用用SolidColorBrush定义,调用 Freeze() 方法,调用之后,其 Dispatcher 属性会被设为 null,于是对象brush可以跨线程访问。Brush brush = (Brush)brushConverter.ConvertFromString("#FF0CF058");brush.Freeze();...原创 2021-07-06 11:19:17 · 137 阅读 · 0 评论 -
WPF DataGrid
datagrid 添加双击事件<DataGrid> <DataGrid.Resources> <Style TargetType="DataGridRow"> <EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/> <Style TargetType="DataGridRow"> </DataGrid.Resource></Data原创 2021-04-16 11:29:35 · 232 阅读 · 0 评论 -
XML结构简介
XML结构简介NodeType:XmlDeclaration eg. <?xml version="1.0"?>WhitespaceComment eg. Element eg. '<'ElementName ArAttribute1 =“1” Attribute2=“2” ‘>’Text eg. ‘<‘Element’>‘Text’<’/Element’>’EndElement eg. ‘<’/ElementName原创 2021-03-18 15:42:34 · 234 阅读 · 0 评论 -
socket通讯
同步通讯Socket remoteSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);remoteSocket.SendTimeout = 2000;remoteSocket.ReceiveTimeout = 2000;原创 2021-03-09 13:59:19 · 124 阅读 · 0 评论 -
C# IPC pipe管道通讯
PipeServerusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.IO.Pipes;using System.Threadin原创 2021-01-06 16:39:35 · 449 阅读 · 0 评论 -
LINQ (语言集查询)
实现了IEnumerable接口的类型的实例可以用where数组,list等都可以使用LINQ示例/******筛选*******/var racers = form r in Formulal.GetChampions() where r.Wins>15 && (r.Country == "Brazil"||r.Country == "Austria") select r;foreach(var r in racers){ console.WriteL原创 2020-12-22 14:54:28 · 112 阅读 · 0 评论 -
string,stringBuilder,Regex(正则表达式)
string类功能非常强大方法作用Compareright-aligned 比较字符串Concat把多个字符串实例合并为一个·Copy To把特定数量的字符从选定的下标复制到数组的一个全新实例中Format格式化IndexOf定位字符第一次出现的位置IndexOfAnyInsertJoinLastIndexOfLastIndexOfAnyPadLeftReplease替换字符或字符串Spli原创 2020-12-21 15:23:19 · 370 阅读 · 0 评论 -
事件
事件需要委托实现,事件的流程如下:发布器类订阅器类触发实例化发布器实例化订阅器注册触发(注销)示例/*发布器*/public class EventTest{ private int value; public delegate void NumManipulationHandler(); pubic event NumManipulationHandler ChangeNum; protected virtual void OnNumChanged() {原创 2020-12-21 11:26:54 · 135 阅读 · 1 评论 -
多播委托
void Action < T t > 可以实现多播委托static void Main(string[] args){ Action<double> operations = MathOperations.MultiplyByTwo;//委托方法1 operations += MathOperations.Square;//委托方法2(多播) ProcessAndDisplayNumber(operations,2.0); ProcessAndDisplayNumber原创 2020-12-18 12:07:54 · 108 阅读 · 0 评论 -
运算符小结
条件运算符condition ? true_value:false_valueint x = 1;string s=x+" ";s+=(x==1? "man":"men");Console.WritheLine(s);checked 和 unchecked运算符checked 溢出检查,抛出OverflowExceptionunchecked 禁止溢出检查byte x =255;unchecked //or checked{ x++;}Console.WriteLine(x.原创 2020-12-18 10:55:29 · 100 阅读 · 0 评论 -
数组,枚举,元组,字典
一维数组int[] myArray;//声明myArray = new int[4];//初始化int[] myArray = new int[4];//声明+初始化int[] myArray = new int[4]{4,8,9,9};int[] myArray ={4,8,9,6};自定义类型的数组public class Person//定义person类{ public string FirstName{get;set;} public string LastName{get;原创 2020-12-17 16:17:04 · 227 阅读 · 0 评论 -
C#时间日期处理及版本处理
1 DateTime 日期格式语法示例(2016-05-09 13:09:55:2350)格式说明DateTime.Now.ToString(““yyyy-MM-dd HH:mm:ss.ff””)2016-05-09 13:09:55.45自定义格式DateTime.Now.ToString()2016/5/9 13:09:55短日期 长时间DateTime.Now.ToString(“d”)2016/5/9短日期DateTime.Now.ToStrin原创 2020-10-15 11:44:06 · 253 阅读 · 0 评论 -
C#自动引用Debug | Release版本的dll
自动引用Debug | Release版本的dll的方法创建$(Configuration)文件夹,并复制dll文件到该文件夹(任意版本的dll都可以)文本格式打开.csproj工程文件,按下面方法修改修改前:<ItemGroup> <Reference Include="ClassLibrary1,Version=1.0.0.0,Culture=neutral,processorArchitecture=MSIL"> <Spec原创 2020-06-23 14:48:27 · 1249 阅读 · 0 评论 -
Lambda函数
Lambda表达式简介简单举例用lambda表达式简化委托简介符号 =>,读作 goes to作用 直接使用=>查询,代替foreach或for循环Lambda表达式是一种匿名函数,Lambda 用在基于方法的 LINQ 查询中,作为诸如 Where 和 Where 等标准查询运算符方法的参数简单举例返回classcode为1001的list 或1001号学生 List<Student> list1001=StudentList.where (t=>t原创 2020-06-09 10:58:24 · 250 阅读 · 0 评论 -
c#类型转化 is,as(尽量使用as,少用类型强制转换)
is 判断变量类型是否一致class manager:person{};manager p = new manager();bool result = p is person;//result = true;as 判断后,类型一致就会转换,类型不一致返回nullclass manager:person{};manager p = new manager{};person result = p as person?;//必需有问号隐式转换int i = 10;long.原创 2020-06-08 17:01:55 · 228 阅读 · 0 评论 -
C# 命名空间 类 字段,属性,方法,变量, 参数
命名空间 类 字段 方法外的变量,一般为私有 属性 保护字段,set为写,get为读, value为内置隐藏变量 方法(参数) 变量 在方法内 参数在方法间传递 实际参数传递 方法(var 参数) 引用参数传递 方法(ref var 参数),调用时也要加(ref 参数),等同于参数的地址(指针) 可变参数传递 方法(params var 参数),调用时不需要再写(params) ...原创 2020-06-08 14:56:22 · 761 阅读 · 0 评论 -
C# for excel12.0 and more
DataSet ds = new DataSet(); string filesurffix = System.IO.Path.GetExtension(sourcePath); string strConn = ""; if (filesurffix == ".xls") strConn = "Provider = Microsoft.ACE.OLEDB.12.0;" + "Data Source =...原创 2020-06-02 09:29:04 · 210 阅读 · 1 评论