EF CORE访问Sqlite和mysql
摘要:.net8 vs2022 v17.9.6调试通过。 如题,和其他ef core用法高度相似。 安装一个“Microsoft.EntityFrameworkCore.Sqlite”即可。 模型类: 1 internal class D1Context:DbContext 2 { 3 protected
阅读全文
posted @
2024-05-21 21:28
万金流
阅读(289)
推荐(0) 编辑
C#数据库通用访问类v21--ADO.NET
摘要:本类可以应对主流数据库的访问。 带参操作可以有效避免sql注入漏洞。 访问mysql的时候,需要使用到一个叫mysql.data.dll的类,大家可以自行在网上寻找。 代码如下: 1 using System; 2 using System.Collections.Generic; 3 using
阅读全文
posted @
2021-04-27 17:43
万金流
阅读(423)
推荐(0) 编辑
利用反射访问任意实体类
摘要:如题。 可以为以后统一的实体类操作做准备。 以下代码.net5调试通过。 实体类Person: using System; using System.Collections.Generic; using System.Text; using System.ComponentModel.DataAnn
阅读全文
posted @
2020-11-20 22:42
万金流
阅读(157)
推荐(0) 编辑
字典
摘要:字典,即“键-值”对,形容可以像翻字典一样,根据索引找到内容。 c#用dictionary实现,java用map实现。 内部算法的关键就是快速查找键值,微软和甲骨文公司会去考虑。 用法例程如下: c#: var a = new Dictionary<string, string>(); a.Add(
阅读全文
posted @
2020-11-20 11:40
万金流
阅读(280)
推荐(0) 编辑
顺序表(list)对类对象排序
摘要:可以使用实现比较接口的方法,直接用sort排序。 如c#: class Person1:IComparable<Person1> { public string Xm { get; set; } public int Nl { get; set; } public int CompareTo(Per
阅读全文
posted @
2020-11-20 11:38
万金流
阅读(363)
推荐(0) 编辑
双色球随机选【代码】
摘要:如题,代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { c
阅读全文
posted @
2020-07-20 00:10
万金流
阅读(969)
推荐(0) 编辑
反射的理解(含一点xml)
摘要:我理解的反射,大概就是各种“找找找”。以下“类名”,均为Type类型(由“名称空间.类名”构成)。 根据类对象,找到类名。 根据一个字符串,找到类名; 有了类名,找到它包含的属性、方法。 有了类名,还可以创建它的实例。 有了3,可以获取类对象的属性值。 会了这几点,应该就算是会了反射。怎么用,就看你
阅读全文
posted @
2020-06-12 17:46
万金流
阅读(271)
推荐(0) 编辑
c#背包问题代码
摘要:代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { clas
阅读全文
posted @
2020-05-25 21:00
万金流
阅读(691)
推荐(0) 编辑
利用反射,把数组里的数据变成指定类对象里的
摘要:朋友遇到的一个问题: 从文本里读出的字符串("张三","20"...),类型以字符串形式已知("string","int"....) 希望转换成类对象。 数据多的情况下,频繁使用反射有可能影响效率,故写了个小demo如下: Person类: 1 class Person 2 { 3 public s
阅读全文
posted @
2020-01-08 17:45
万金流
阅读(570)
推荐(0) 编辑
冒泡排序法vs快速排序法
摘要:闲着没事,想思考一下两种排序法的直观对比,写了个小程序,代码如下,分析见后面: class Program { static DateTime t1, t2; static TimeSpan ts1, ts2,ts3; static int c1 = 0, c2 = 0,c3=0; static v
阅读全文
posted @
2019-06-03 20:01
万金流
阅读(1325)
推荐(0) 编辑