
C#
文章平均质量分 53
C#相关
Jo.H
Daily self reflection
展开
-
C#_读写Txt文档
IO读写文件原创 2019-03-01 18:52:42 · 281 阅读 · 0 评论 -
超简单的Google Protobuf的使用手册
简单易懂的protobuf使用和开发流程,从零开始原创 2022-12-23 21:21:43 · 2893 阅读 · 0 评论 -
Unity_Mono对象的单例模式
MonoBehaviour单例基类原创 2019-06-17 16:04:50 · 802 阅读 · 0 评论 -
在文本的标记中添加新内容
/// 重写脚本文件原创 2021-01-22 11:13:38 · 272 阅读 · 0 评论 -
C#格式化JSON数据
格式化json原创 2020-08-26 15:16:55 · 2605 阅读 · 0 评论 -
C#_String的方法
string str;int i;1、获取。1.1 获取字符串中字符的个数。str.length;(返回值类型为int)1.2 通过指定的位置,获取该位置上的字符。char charAt(index);1.3 通过字符串获取到索引位。str.IndexOf('字符');(返回值类型为int,其中字符串的第一个位置为0)通过指定的字符获取该字符在字符串中...原创 2019-03-06 16:28:58 · 524 阅读 · 0 评论 -
C# _利用正则表达式验证邮箱有效性
using System;using System.Text.RegularExpressions;class ValidateEmail{ static void Main(string[] args){ string pattern = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]...原创 2019-03-06 16:28:55 · 1136 阅读 · 0 评论 -
动态生成C#代码cs文件_CSharp
动态生成脚本文件(不能添加到程序集),根据数据群代码生成完整的C#脚本文件,例如根据数据库等自动生成接口、类、结构、或者枚举等,需要用到的引用:using System.CodeDom;using System.CodeDom.Compiler;using System.Reflection;//实例 public static void BuildClass(...原创 2019-06-27 10:57:35 · 6352 阅读 · 3 评论 -
System.DateTime
DateTime转化成long(时间戳)public static long DateTimeToLong(System.DateTime time){ System.DateTime dateTime= TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); lon...翻译 2019-06-27 10:57:12 · 1165 阅读 · 0 评论 -
C#_获取本地IP地址
using System.Net; void GetLocalIp() { //获取本机名称 string hostname = Dns.GetHostName(); //获取本机DNS信息 IPHostEntry localhost = Dns.GetHostEntry(hostname); /...原创 2019-03-06 16:29:03 · 523 阅读 · 0 评论 -
C#_委托和事件_匿名方法_lamuda表达式
using System.Collections;public class CallClass {//定义一个委托,可以声明在类里面,也可以在外面 public delegate void DelegateFun(int i);//定义一个委托类型的对象,DelegateFun中的传入是方法名,传入的这个方法的参数种类和数量要一致 D...原创 2019-03-06 16:29:06 · 599 阅读 · 0 评论 -
C# _Enum枚举
enum MyEnum{a,b,c,d,e,f}MyEnum myEnum;string[] str="";//获取enum中的成员名称,转换成stringforeach(string strEnum in System.Enum.GetNames(myEnum.GetType())) {print(strEnum);}//把enum中元素转化成intpr...原创 2019-03-06 16:29:09 · 540 阅读 · 0 评论 -
C#_Attribute特性
C#预定义的AttributeAttributeUsage:格式为[AttributeUsage(AttributeTargets , (bool) AllowMultiple ,(boll) Inherited )]放在继承Attribute的类前面,参数AttributeTargets为Attribute的使用范围;Attribute的适用范围/*All:类Asse...原创 2019-03-06 16:29:13 · 202 阅读 · 0 评论 -
C#单例模式
第一种最简单,但没有考虑线程安全,在多线程时可能会出问题public class Singleton{ private static Singleton _instance = null; private Singleton() { } public static Singleton CreateInstance() { if (_...原创 2019-03-01 18:55:01 · 2672 阅读 · 0 评论 -
C#_输出程序集
usingSystem;using System.Reflection;class DebugObjectType { internal void FunctionType(object o) { //类型 Type objType = o.GetType();//程序集构造块(字段、方法) ...原创 2019-03-01 18:54:39 · 166 阅读 · 0 评论 -
C#_扩展方法
扩展方法定义为静态方法,对于封装类的也可以添加新的方法,但并不能访问类的私有变量public static class ClassExtension{// 参数类型前要加thispublic static void DebugString( this string s ){Console.WriteLine( "这是扩展String类的的一个新方法,输出自身字符串" + s)...原创 2019-03-01 18:54:13 · 136 阅读 · 0 评论 -
C#_对string字符串使用MD5加密
using System.Security.Cryptography;public string StringToMD5 ( string str ) { MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); md5Hasher.ComputeHash(Encoding.Default.Get...原创 2019-03-01 18:52:16 · 1017 阅读 · 1 评论 -
C#_获取对象的名称
using System;using System.Linq.Expressions;//放到扩展类里 // 返回对象的名称 static public string GetObjectName<T>(Expression<Func<T>> memberExpression) { MemberExpress...原创 2019-03-01 18:50:53 · 2686 阅读 · 0 评论 -
查看文件目录下的文件和文件夹
DirectoryInfo //文件夹类FileInfo//文件类DirectoryInfo TheFolder = new DirectoryInfo(path); FileInfo[] fileInfo = TheFolder.GetFiles(); //遍历文件 foreach (FileInfofile in fileI...原创 2019-03-01 18:50:16 · 533 阅读 · 0 评论