C#学习
文章平均质量分 60
Rakutan
个人笔记
展开
-
【c#】金钱数值处理
需要注意的是,如果你的游戏涉及到大量的金钱计算,确保在处理数值时不会溢出,同时也要注意在UI展示时格式化输出,以确保玩家可以清晰地看到大额金钱数值。这里的 {0:n0} 使用了标准的数字格式化字符串,它将数字格式化为带有逗号的形式,增强了可读性。在C#中,可以使用字符串的格式化功能或者标准的货币格式化来处理这个任务。另一种方法是使用货币格式化,这可以确保正确显示货币符号和小数点位置,即使你的金钱数值是整数。整数表示: 如果你的金钱数值是整数,没有小数部分,使用整数类型可以简化计算,减少内存占用。原创 2023-12-10 01:17:32 · 498 阅读 · 1 评论 -
【深入c#】第一章
c#原创 2022-07-28 10:03:14 · 102 阅读 · 0 评论 -
编程 计算
不使用第三方变量交换a和bA:原理是利用两个数的差值不会发生改变 void swap(int a,int b) { a = a - b; b = b + a;//8 a = b - a; print(a + " " + b); }原创 2021-12-13 18:14:40 · 507 阅读 · 0 评论 -
Exception异常
int MyExceptiontEST(int num) { try { Debug.Log("try"); return 5 / num; } catch (System.Exception e) { Debug.Log("catch"); ...原创 2021-12-13 17:51:51 · 123 阅读 · 0 评论 -
static 静态类 方法 变量
当类第一次被加载时,会对类中的静态变量先按顺序进行分配内存空间,当全部分配完内存空间之后,再对静态变量按顺序赋值。 int x = y; int y = 5;程序会报错,因为x找不到y的值(y在栈中的值) int x = y; static int y = 5; static void Main() { Console.WriteLine(x); Console.WriteLine(y); } /*Ou.原创 2021-12-13 16:49:32 · 234 阅读 · 0 评论 -
内存 IL过程 装箱 拆箱
int i = 4;2 object o = i;3 object o2 = o;4 Console.WriteLine(ReferenceEquals(o, o2)); //true5 o = 8;6 Console.WriteLine(ReferenceEquals(o, o2)); //false7 8 Console.WriteLine("i={0原创 2021-12-12 22:32:12 · 158 阅读 · 0 评论 -
内存 int long object
int i = 1; object o = i;//装箱 int j = (int)o;//拆箱int在内存中占4字节,long占8字节,赋值给object的int类型,则object也占4字节,如果是long则为8字节。测试代码 int i = 6; print("int:"+sizeof(int)); System.Object o = i; print("object:"+System.Runt.原创 2021-12-12 18:42:15 · 233 阅读 · 0 评论 -
struct结构与内存
sizeof(int)是4,意味着int是4字节。原创 2021-12-12 14:45:04 · 826 阅读 · 0 评论 -
实例化方式的比较 Activator和new
void Start() { System.Activator.CreateInstance<Food>().Eat(); } void Start() { Create<Food>().Eat(); } T Create<T>()where T:new () { ...原创 2021-12-12 12:20:28 · 324 阅读 · 0 评论 -
ref和out
当我们想把一个值类像引用类型一样,别的类调用了某方法就能改变这个类的值类型,便可以使用ref、out这种参数传递。 void Start() { //print(GameUtil.RunRandom(0.5f)); int age = 10; print("age now"+age); Grow(ref age); print("grow age" + a原创 2021-12-12 12:06:38 · 128 阅读 · 0 评论 -
继承 多态的理解
当父类想让子类实现同一方法的不同行为时,需要用virtual修饰,而且会要求子类必须重写这个方法。在子类重写父类的方法过程中,如果使用newpublic class Animal { public virtual void Eat() { Console.WriteLine("Animal eat"); } } public class Cat : Animal { public n原创 2021-12-10 11:54:06 · 304 阅读 · 0 评论