C#
Csharp的学习和分享
斗乐八神
积跬步至千里,积小流成江海。
展开
-
【C#异常捕获】C#中Try-Catch语句真的影响程序性能吗?
很多帖子都分析过Try-Catch的机制,以及其对性能的影响。但是并没有证据证明,Try-Catch过于损耗了系统的性能,尤其是在托管环境下。转载 2023-08-08 14:00:25 · 322 阅读 · 0 评论 -
C# 获取可执行文件EXE(文件夹)路径大全
/获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。结果:X:\xxx\xxx\xxx.exe(.exe文件所在的目录+.exe文件名)结果:X:\xxx\xxx\xxx.exe(.exe文件所在的目录+.exe文件名)结果:X:\xxx\xxx\xxx.exe(.exe文件所在的目录+.exe文件名)结果:X:\xxx\xxx\(.exe文件所在的目录+“”)结果:X:\xxx\xxx(.exe文件所在的目录)//获取和设置包含该应用程序的目录的名称。原创 2022-10-24 17:28:32 · 5831 阅读 · 0 评论 -
C# 打开指定路径的文件(文件夹)
代码 string filePath = "XXX";//文件(文件夹)路径 System.Diagnostics.Process.Start(filePath);原创 2021-06-25 15:57:03 · 7921 阅读 · 4 评论 -
Unity 文件夹拷贝(复制)
参考代码/// <summary> /// 拷贝文件夹 /// </summary> /// <param name="srcPath">需要被拷贝的文件夹路径</param> /// <param name="tarPath">拷贝目标路径</param> private void CopyFolder(string srcPath, string tarPath) {原创 2021-06-22 15:59:05 · 2336 阅读 · 2 评论 -
阶乘实现(C#递归)
开门见山代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace test{ class Program { static void Main(string[] args) { int n; int.TryP原创 2020-11-02 23:05:37 · 168 阅读 · 0 评论 -
lua实现c#中的函数重载
lua实现C#中的函数重载C#的函数重载类似于C++、Java等OOP语言,C#函数重载概括起来就是对于多个函数,进行这样的处理时:1 函数的名字必须相同2 函数的参数类型一定不同3 函数的参数个数不同,或者个数可以相同但类型一定不同3 与函数的返回值无关就实现了该函数的重载。例: public void Print(int a) { System.Console.WriteLine(a); } public void Print(i原创 2020-10-13 17:05:24 · 240 阅读 · 0 评论 -
C# 重写一个类似List类的泛型类MyList,实现List类中的一些基本泛型方法
C#中提供的List类首先来看看List类,它是一个泛型(如果对泛型不理解的小伙伴,可以自行百度了解一下),在C#原生List类中的,定义了很多对泛型列表元素的操作的方法,例如:public void Add(T item) //添加泛型元素public void RemoveAt(int index) //移除指定索引的泛型元素public bool Contains(T item) ...原创 2019-08-22 23:56:40 · 1145 阅读 · 0 评论 -
2048游戏的简单实现(C#实现)
游戏规则游戏规则,玩家需要控制所有方块向同一个方向运动,两个相同数字方块撞在一起后会合并成为它们的和,每次操作后会随机生成一个2或者4,最终得到一个“2048”的方块就算胜利。C#代码实现using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Thre...原创 2019-08-17 14:15:46 · 3543 阅读 · 1 评论 -
C#中的矩形数组(多维数组)和锯齿数组
(一)矩形数组矩形数组,又称多维数组,是使用多个索引访问其元素的数组。二维数组的定义:<baseType>[,] <name>;例如,声明和初始化一个二维数组doubleArray,其基本类型是double,3行4列:double[,] doubleArray=new double[3,4];double[,] doubleArray={{1,2,3,4}...原创 2019-08-12 23:55:24 · 1971 阅读 · 0 评论 -
Windows上使用C#控制台应用程序打开指定路径的文件
例如打开Windows操作系统里的cmd.exe(命令行程序)using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Threading;namespace Open_The9_12{ ...原创 2019-08-16 14:44:03 · 2156 阅读 · 0 评论 -
抽象类和抽象方法描述(c#)
用abstract修饰的类叫抽象类,用abstract修饰的方法叫抽象方法。例如:创建一个动物抽象类,里面包含一个抽象方法Say() abstract class Animal//抽象类 { //普通成员属性 public int a; //普通成员方法 public void Test() ...原创 2019-08-15 15:10:41 · 178 阅读 · 0 评论 -
类的继承(c#)
继承的优缺点继承的优点:代码复用便于代码的层次化管理提高代码的可维护性和可扩展性继承的缺点:代码耦合度高,修改父类代码会影响子类...原创 2019-08-15 14:47:24 · 254 阅读 · 0 评论 -
静态类和静态成员(c#)
一、静态成员C#中一个类的静态成员属性和静态成员方法统称为静态成员,其他情况的属性和方法叫做非静态成员。静态成员用修饰符static修饰。//非静态类Rectclass Rect{ public static int x=5;//定义静态成员属性x,初始化等于5 public int y=10;//定义非静态成员属性y,初始化等于10 public void P...原创 2019-08-15 10:01:29 · 168 阅读 · 0 评论 -
C# 计算小字符串出现在大字符串中的次数
C#源码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 求子串出现次数{ class Program { static void Main(string[] ...原创 2019-08-19 20:03:47 · 265 阅读 · 0 评论 -
C# 打乱数组中的数组元素
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace __2019年8月13日{ class Program { static void Main(string[] ...原创 2019-08-13 16:45:16 · 3378 阅读 · 0 评论 -
C#学习 方法篇
一、方法的定义和调用定义一个打印方法,在主方法中调用该方法:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 方法_定义和调用{ class Program { ...原创 2019-08-13 13:08:53 · 1065 阅读 · 2 评论