
C#
文章平均质量分 60
yuxuac
这个作者很懒,什么都没留下…
展开
-
c# - 汉字数字,阿拉伯数字,相互转换
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace DesignPatterns.ChineseNumConvertor{ public class Node { public string Unit { get; set...原创 2020-02-02 12:57:32 · 2524 阅读 · 1 评论 -
c# - entityframework core - switch databases
更换数据库之后,如果旧的Migrations导致数据库错误,可按照以下步骤重新生成Migrations:1. 删除所有existing migrations(包含:DataContextModelSnapshot), 直接文件删除就可以。2. 安装要更换数据库DataProvider的nuget package,例如:SqlServer的nuget package为:Microsoft.En...原创 2020-01-25 13:14:08 · 1600 阅读 · 0 评论 -
c# - CancellationToken Demo
using System;using System.Threading;using System.Threading.Tasks;namespace TaskCancellationTest{ class Program { static void Main(string[] args) { Cancellatio...原创 2020-01-05 12:30:21 · 498 阅读 · 0 评论 -
VSCode - Task.json同时Build多个Projects.
https://stackoverflow.com/questions/52238171/how-to-run-multiple-tasks-in-vs-code-on-build转载 2019-12-27 21:04:39 · 1536 阅读 · 0 评论 -
EntityFramwork Core - Reverse Engineering
基于Db Model->Update数据库Schema:应用migration1:1. 修改你的Db Model2. 执行:Add-Migration migration1 -Context "MyDbContext"3. 执行:Update-Database -Context "MyDbContext"撤销:migration11. 执行:Update-Database ‘...原创 2019-12-20 13:00:11 · 241 阅读 · 0 评论 -
Using .net core with Sqlite+password
1. 在.net framework下设置Sqlite密码,访问数据,重设密码,删除密码。using System;using System.Data.SQLite;namespace ConsoleApp1{ class Program { private const string password = "abc.123"; stat...原创 2019-12-20 12:37:51 · 1663 阅读 · 7 评论 -
Asp.net Core - Custom middleware
public class PrintSomethingMiddleware { private readonly RequestDelegate _next; public PrintSomethingMiddleware(RequestDelegate next) { _next = next; }...原创 2019-12-15 14:41:46 · 191 阅读 · 0 评论 -
Asp.net Core - File Logging
https://nblumhardt.com/2016/10/aspnet-core-file-logger/转载 2019-12-15 11:18:38 · 294 阅读 · 0 评论 -
c# - Expression Tree and Why?
https://www.tutorialsteacher.com/linq/expression-treeusing System;using System.Linq.Expressions;namespace LambdaExpression{ public class Student { public string Name { get; set;...转载 2019-12-12 11:51:37 · 157 阅读 · 0 评论 -
c# - Getting Started with Entity Framework Core: Database-First Development
https://www.codeproject.com/Articles/1209903/Getting-Started-with-Entity-Framework-Core-Databas转载 2019-12-12 10:18:34 · 205 阅读 · 0 评论 -
c# - 控制台程序 合并Dll 不使用任何第三方插件
准备工作:1. 新建一个控制台程序Project:CombinedDlls.2. 再新建一个Class Library Project: ThirdPartyTool,新建一个类Util.cs, 在其中实现一个static的SayHelloTo(string name)方法。3.CombinedDlls引用ThirdPartyTool,并在代码中调用SayHelloTo方法。Sa...原创 2019-12-01 13:41:39 · 591 阅读 · 0 评论 -
c# - events 观察者模式
using System;namespace EventsDemo{ class Program { static void Main(string[] args) { Cat cat = new Cat() { Name = "Tom" }; Mouse mouse1 = new Mouse...原创 2019-11-25 13:42:52 · 132 阅读 · 0 评论 -
c# - struct和class的区别
1. struct不可以有无参数的构造函数2. 如果struct存在构造函数,所有属性必须在构造函数中初始化3. 不可以在struct中直接初始化属性4. struct可以不使用new初始化5. 若struct没有使用new初始化, 所有属性赋值之后, 对象才可以使用6. struct不可被继承7. struct可以实现接口(与class一致)8. struct是值类型,class是...原创 2019-11-25 11:57:41 · 165 阅读 · 0 评论 -
c# - Object Pooling(对象池)
Object pooling的主要目的是提升程序性能。代码会先从Pool中取得已经建好的对象实例,如果Pool中没有对象实例才需要重新创建,以下代码是一个示例:namespace ObjectPool{ using System; using System.Collections; class Program { static void M...原创 2019-11-20 15:52:16 · 1880 阅读 · 0 评论 -
c# - yield
yield关键字可以概括为一句话:对于返回值为集合的函数,使用yield return,可以每次返回集合中一个元素。namespace YieldTest{ using System; using System.Collections.Generic; class Program { static void Main(string[] arg原创 2016-01-22 12:16:18 · 436 阅读 · 0 评论 -
c# - async await
Console:using System;using System.Threading;using System.Threading.Tasks;namespace ConsoleApplication37{ class Program { public static Random R = new Random(); public st原创 2017-06-19 13:28:06 · 450 阅读 · 0 评论 -
Regex - 正则表达式 车牌号 国内
判断是否是合法的国内车牌号:基于http://baike.baidu.com/view/64583.htm public static readonly Regex RegexValidVehicleRegistrationNumber = new Regex(@"^(([\u4e00-\u9fa5]{1}[A-Z]{1})[-]?|([wW][Jj][\u4e00-\u9fa5原创 2016-08-16 13:47:22 · 9115 阅读 · 4 评论 -
c# - Timer中的一个问题
我们知道,System.Threading.Timer可以定时每隔一段时间执行一次任务。不知道大家有没有想过,如果任务执行时间比较长,Interval到期之后会发生什么;是会结束当前的线程,还是会重新启动一个线程?下面代码我们模拟一下,任务执行时间5s, Interval=2s的运行情况:using System;using System.Timers;namespace Tim原创 2017-08-17 14:27:04 · 1412 阅读 · 0 评论 -
c# - async 异步 方法 怎么 调用
using System;using System.Net.Http;using System.Threading;namespace AsyncTest2{ class Program { static void Main(string[] args) { Console.WriteLine("Start down原创 2017-08-18 16:35:17 · 10606 阅读 · 1 评论 -
c# - Serialize and Deserialize, 序列化 反序列化 泛型
泛型 序列化 反序列化 static public void Serialize(T obj, string xmlpath) { XmlSerializer serializer = new XmlSerializer(typeof(T)); using (StreamWriter writer = new StreamWr原创 2013-11-19 20:56:54 · 4838 阅读 · 0 评论 -
c# - 压缩图片工具
工具类:using System;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.Linq;namespace resizetool{ /// /// Class contaning method to resize an i原创 2017-05-10 20:55:23 · 650 阅读 · 0 评论 -
c# - 二叉树的遍历
using System;using System.Collections.Generic;namespace BinaryTree{ public class BinaryTree { public T Val { get; set; } public BinaryTree Left { get; set; } public原创 2017-04-19 18:05:48 · 2624 阅读 · 0 评论 -
Caching in .Net
http://www.cnblogs.com/Caceolod/articles/1654126.html原创 2015-11-17 15:12:46 · 508 阅读 · 0 评论 -
c# - 去除XML中的namespace
static string RemoveNamespaces(string xml) { var xmlDoc = XElement.Parse(xml); xmlDoc = stripNS(xmlDoc); return xmlDoc.ToString(); } static原创 2017-03-22 10:37:37 · 1810 阅读 · 0 评论 -
sql - 表结构生成类脚本
declare @TableName sysname = 'Claim'declare @Result varchar(max) = 'public class ' + @TableName + '{'select @Result = @Result + ' public ' + ColumnType + NullableSign + ' ' + ColumnName + ' {转载 2017-03-10 18:05:14 · 547 阅读 · 0 评论 -
c# - 外部对象作为参数调用方法时需要注意的问题
结论:1. 如果方法参数是类,则会被当作引用类型,无论是否使用ref,值都会在调用方法时被修改。 2. 如果方法参数是基本类型,如int或者string,不使用ref,则值不会在调用方法时被修改;使用ref,值会在调用方法时被修改。定义两个类: public class IntClass { public int I { get; set; }原创 2017-02-04 11:39:22 · 2393 阅读 · 0 评论 -
c# - 常见错误
// 如果可空类型不初始化,则其值不参与计算 decimal? a = null; a += 20; Console.WriteLine(a); // 修正: //decimal? a = 0; //a += 20; //Cons原创 2017-02-28 13:20:30 · 603 阅读 · 0 评论 -
c# - 序列化 部分 XML
prpLregistEx innerObject; XmlTextReader reader = new XmlTextReader(@"C:\Users\Cui\documents\visual studio 2013\Projects\MtachDriver\MtachDriver\最新报文.xml"); read原创 2014-04-10 14:36:42 · 679 阅读 · 0 评论 -
c# - if 条件中果有多个&& 或 || 条件,其执行顺序是怎样的?
首先,为了避免歧义,特此说明:我们不是讨论&&优先于||执行,我们讨论如果一个If中有多个&&;或一个if中有多个||;他们的执行顺序是什么。答案是:从左至右。示例: static void Main(string[] args) { int a = 0; // OK原创 2016-12-30 15:34:23 · 47345 阅读 · 4 评论 -
c# - Resolve<T> to create instance
using System;namespace CSharpTesting{ class Program { static void Main(string[] args) { AttackService.Resolve().Attack(); AttackService.Resolve().At原创 2016-09-26 15:18:51 · 2135 阅读 · 0 评论 -
c# - 格式化 Json
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using Newtonsoft.Json;namespace FormatJson{ class Program原创 2017-12-22 19:33:25 · 1783 阅读 · 0 评论 -
c# - 顺时针访问二维数组
顺时针访问二维数组,从1开始赋值至最后一个节点。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace TraverseMatrix{ class Program { ...原创 2018-03-21 14:11:25 · 843 阅读 · 0 评论 -
c# - Performance Checker
写这个类的目的是想测试部分代码的执行时间,比起直接在代码里加DateTime span , 它使用起来更方便一些。你也可以随时控制什么时候输出性能信息。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System原创 2012-09-22 10:53:49 · 720 阅读 · 0 评论 -
c# - Owin Katana
https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/an-overview-of-project-katana原创 2019-09-23 22:39:36 · 277 阅读 · 0 评论 -
c# - 文字 中心 旋转
public static void DrawRotatedTextAt(Graphics gr, float angle, string txt, float x, float y, Font the_font, Brush the_brush) { // Text rectangle var fontRect =...原创 2019-09-22 17:03:07 · 1161 阅读 · 0 评论 -
c# - 线程 Thread AutoResetEvent 与 ManualResetEvent
using System;using System.IO;using System.Text;using System.Threading;namespace ThreadingDemo{ /// <summary> /// AutoResetEvent及ManualResetEvent: 主要目的是使线程同步执行: /// 1. 线程1:在当前线...原创 2019-07-22 23:53:18 · 428 阅读 · 0 评论 -
c# - double 与 decimal
Double与Decimal的区别如下:class Program { static void Main(string[] args) { double a = 0.3 - 0.2; double b = 0.2 - 0.1; Console.WriteLine(a == b); ...原创 2019-06-25 00:05:27 · 5289 阅读 · 0 评论 -
c# - 分割大文本文件
将一个大的文本文件分割成若干个小文本文件。 public static void Split() { int lineOfEach = 10000; int fileIndex = 1; string file = @"D:\Work\YourBigFile.csv"; ...原创 2019-05-10 10:33:44 · 1488 阅读 · 1 评论 -
c# - 存储二维数组
using System;using System.IO;using System.IO.Compression;namespace ArrayTest{ class Program { static void Main(string[] args) { ushort[,] orignalArray = new u...原创 2019-04-19 15:28:54 · 2600 阅读 · 0 评论 -
c# - 指定权限访问某个文件路径
namespace Tools{ #region Using directives. // ---------------------------------------------------------------------- using System; using System.Security.Principal; using System.Runtime.Interop...转载 2019-04-04 09:58:30 · 719 阅读 · 0 评论