
C#基础
文章平均质量分 78
little_two_two
这个作者很懒,什么都没留下…
展开
-
C#基础学习之【2】数据类型
C#是一种强制类型语言,在使用任意一个对象前,必须声明这个对象的类型。C#的类型分为两个大类:值类型和引用类型。两者的主要区别是值在内存中的存储方式不同,值类型的实例通常是在栈上静态分配的,引用类型的对象则总是在进程堆中动态分配。值类型包括:内置类型、结构、枚举。引用类型包括:类和委托1、C#内置类型C#内置类型类型大小/字节.NET类型说明原创 2015-02-04 17:26:43 · 711 阅读 · 0 评论 -
C#判断大小端并转换int数据
private static bool _isBigEndian; private static bool _isEndianChecked = false; private static bool IsBigEndian() { if( !_isEndianChecked ) { _isEndianChecked = true; int nCheck = 0x01aa原创 2015-10-22 00:29:25 · 3771 阅读 · 1 评论 -
匹夫细说C#:庖丁解牛迭代器,那些藏在幕后的秘密
转载自:http://www.cnblogs.com/murongxiaopifu/p/4437432.htmlc#语言规范阅读目录0x00 前言0x01 你好,迭代器0x02 原来是状态机呀0x03 状态管理0x04 总结回到目录0x00 前言在匹夫的上一篇文章《匹夫细说C#:不是“栈类型”的值类型,从生命周期聊存储位置》的最后,匹夫以总结和后转载 2015-11-20 01:31:42 · 638 阅读 · 0 评论 -
C#中绝对路径转相对路径
在一份代码中看到了一个路径转换的方法,贴出来共享。具体是谁的代码也不知道,如有冒犯请留言。 /// /// 绝对路径转相对路径 /// /// 基本路径 /// 绝对路径 /// strFullPath相对于strBasePath的相对路径 public static string原创 2015-11-02 23:43:30 · 3485 阅读 · 0 评论 -
C#迭代器原理
转载自:http://www.cnblogs.com/eagle1986/archive/2011/12/05/2276293.html迭代器概述迭代器是可以返回相同类型的值的有序序列的一段代码。迭代器可用作方法、运算符或 get 访问器的代码体。迭代器代码使用 yield return 语句依次返回每个元素。yield break 将终止迭代。有关更多信息,请转载 2015-11-19 10:11:46 · 2404 阅读 · 0 评论 -
C#迭代器
转载自:http://www.cnblogs.com/kenshincui/archive/2011/04/04/2005297.html摘要:迭代器是C#2.0中添加的功能,它能够使我们在类或结构中支持foreach迭代,而不必实现整个IEnumerable/IEnumerable接口。今天我们就一块看一下什么是c#中的迭代器吧。主要内容:1.foreach的运行机制转载 2015-11-19 09:58:29 · 474 阅读 · 0 评论 -
委托的简化语法,聊聊匿名方法和闭包
转载自:http://www.cnblogs.com/murongxiaopifu/p/4750964.html?utm_source=tuicool&utm_medium=referralc#语言规范阅读目录0x00 前言0x01 不必构造委托对象0x02 匿名方法初探0x03 使用匿名方法省略参数0x04 匿名方法和闭包0x05 匿名方法如何捕获外部变量0x转载 2015-11-20 01:02:05 · 599 阅读 · 0 评论 -
C#基础之IEnumerable和IEnumerator
转载自:http://www.omuying.com/article/158.aspxC# 提供了 IEnumerable 和 IEnumerator 两个接口用来支持 foreach 语法,通过查看帮助文档,我们可以知道 IEnumerable 只提供了一个 GetEnumerator() 方法,而 IEnumerator 提供了一个属性(Current)和两个方法(MoveNext()转载 2016-01-22 23:03:04 · 645 阅读 · 0 评论 -
C#的Activator.CreateInstance方法
转载自:http://www.cnblogs.com/lmfeng/archive/2012/01/30/2331666.htmlActivator.CreateInstance 方法 (Type) 使用与指定参数匹配程度最高的构造函数来创建指定类型的实例。 命名空间:System程序集:mscorlib(在 mscorlib.dll 中) C# p转载 2015-12-08 00:05:23 · 12039 阅读 · 0 评论 -
C#单例模式的泛型定义
取自某热门网游using System;public class Singleton where T : class, new(){ private static T _Instance; public static T Instance { get { if (Singleton._Instance == null) { Singleton._Ins转载 2015-12-08 00:17:00 · 2686 阅读 · 0 评论 -
C#反射详解
转载自:http://www.cnblogs.com/yazdao/archive/2012/03/31/2426458.html反射的定义:审查元数据并收集关於它的类型信息的能力,元数据(编辑后的基本数据单元)就是一大堆表,编译器会创建一个类定义表,一个字段定义表,一个方法定义表等,System.Reflection命名空间包含的几个类,允许你反射(解析)这些元数据的代码转载 2015-12-07 23:24:40 · 549 阅读 · 0 评论 -
C#DateTime各种使用
转载自:http://www.cnblogs.com/computer-lzy/archive/2012/07/20/2600506.html获得当前系统时间: DateTime dt = DateTime.Now;Environment.TickCount可以得到“系统启动到现在”的毫秒值DateTime now = DateTime.Now;Console.WriteLine(转载 2016-02-04 00:09:13 · 1412 阅读 · 0 评论 -
将本地时间转化为距1970.1.1秒数后转化为本地时间
做游戏需要服务器与客户端时间通信,下面记录一下某个游戏时间通信的例子private static DateTime m_startTime = new DateTime(1970, 1, 1); public static DateTime GetServerDateTime() { TimeSpan timeSpan = (DateTime.UtcNow - new DateTime原创 2016-04-25 19:04:14 · 2503 阅读 · 0 评论 -
C# override与overload
转载自:http://www.cnblogs.com/netlyf/archive/2009/09/08/1562642.html重载应该叫overload,重写叫override;重载某个方法是在同一个类中发生的!重写是在子类中重写父类中的方法。1.override: 父类:public virtual string ToString(){return "a";}转载 2016-05-31 23:19:17 · 508 阅读 · 0 评论 -
C# List内存分配
转载自:http://www.cnblogs.com/visionwang/archive/2013/04/24/3041379.html有些时候由于代码的问题(确切地说是不了解framework的内存使用机制)也会导致outofmemory,一般占用大内存的情况就是list和hashtable2种结构,而这2种数据结构实际上都是使用数组作为容器存放元素的,由于数组是定长结构所以当达到转载 2016-05-31 23:35:27 · 5398 阅读 · 0 评论 -
C#弱引用
转载自:http://www.cnblogs.com/mokey/archive/2011/11/24/2261605.html一:什么是弱引用 了解弱引用之前,先了解一下什么是强引用 例如 : Object obj=new Object(); 就是一个强引用,内存分配一份空间给用以存储Object数据,这块内存有一个首地址,也就是obj所保存的数据转载 2016-08-29 14:31:59 · 646 阅读 · 0 评论 -
游戏中的位操作
void IntToColor( int val ) { Color black = Color.black; black.r = (val & 1); black.g = (val >> 1 & 1); black.b = (val >> 2 & 1); black.a = (val >> 3 & 1); }通过位操作方法,可以省一些空间。大家要熟练在游戏中使原创 2016-12-20 00:03:14 · 434 阅读 · 0 评论 -
C#Attribute的使用
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Reflection;class Program{ static void Main(string[] args) {原创 2017-01-11 00:08:02 · 497 阅读 · 0 评论 -
C#的List排序
private static int CompareListBig( int_a, int_b)//由大到小{ int _temp = _a - _b; if (_temp < 0) return 1; if (_temp > 0) return -1; return 0;}private static int CompareL原创 2015-09-17 15:21:03 · 437 阅读 · 0 评论 -
[C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
[C#/ASP.NET]中List真的非常好用。一个例子简单说明一下List简单介绍:List.Sort() → 排序TList.Find() → 找出一個TList.FindAll() →找出多個TList.Exist() →判斷T是否存在 示例代码: 页面文件GenericList.aspx1234转载 2015-09-17 15:37:09 · 4212 阅读 · 0 评论 -
C#StringBuilder的使用
代码来自MSDNusing System;using System.Text;public sealed class App { static void Main() { // Create a StringBuilder that expects to hold 50 characters. // Initialize the Str原创 2015-09-02 00:24:37 · 671 阅读 · 0 评论 -
C#基础学习之【3】多态与静态对象的使用1
1、多态的使用using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{ // 定义一个叫Enemy的基类 public class Enemy { //构造函数 public Enemy()原创 2015-02-04 17:42:51 · 807 阅读 · 0 评论 -
C#基础学习之【6】委托的使用
using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{ public class ImplementingClass { // 2. 定义用于委托调用的方法,它的返回值和参数列表必须与委托一致 public int WhichI原创 2015-02-05 09:44:37 · 578 阅读 · 0 评论 -
C#基础学习之【4】字符串的操作
using System;using System.Collections;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{ class Program { static void Main(string[] args) {原创 2015-02-05 09:23:26 · 635 阅读 · 0 评论 -
C#基础学习之【5】数组的操作
using System;namespace ArrayDemo{ class MainClass { public static void Main (string[] args) { //first type int[] array1 = new int[5]; array1 [0] = 1; array1 [1] = 9; array1 [2]原创 2015-02-05 09:41:27 · 566 阅读 · 0 评论 -
C#基础学习之【7】事件的使用
using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{ class Program { // 1. 定义一个类,继承EventArgs,它用于存储事件中需要传递的数据 public class Network原创 2015-02-05 10:04:31 · 575 阅读 · 0 评论 -
C#基础学习之【1】文件操作
本文设备环境:Mac Monousing System;using System.Collections.Generic;using System.Text;namespace HelloWorld{ class MainClass { public static void Main (string[] args) { //默认的路径为bin/Debug s原创 2015-02-03 11:05:13 · 826 阅读 · 0 评论 -
C#经典排序
转载自:http://blog.youkuaiyun.com/asd237241291/article/details/89416761.选择排序class SelectionSorter { private int min; public void Sort(int[] arr) {转载 2015-02-26 13:13:18 · 622 阅读 · 0 评论 -
C#中Event和Delegate的混合使用
转载自:http://blog.youkuaiyun.com/smstong/article/details/5350798C#用户可能会发现,event关键字有时候可有可无。[c-sharp] view plaincopynamespace ConsoleApplication3 { class Program转载 2015-03-25 11:13:45 · 772 阅读 · 0 评论 -
C#中string转int
转载自:http://www.cnblogs.com/nzbbody/p/3317639.htmlC# int与string转化1、int-->string1 int a = 15;2 string s1 = a.ToString();3 string s2 = Convert.ToString转载 2015-03-05 10:50:38 · 2540 阅读 · 0 评论 -
C#的split用法
转载自:http://www.cnblogs.com/yugen/archive/2010/08/18/1802781.html1、用字符串分隔: using System.Text.RegularExpressions;string str="aaajsbbbjsccc";string[] sArray=Regex.Split(str,"js",RegexOptions.转载 2015-03-06 16:58:53 · 686 阅读 · 0 评论 -
C#中List的排序
C#中List可以存储任意类型的对象,本文实现一种较为简单的排序方法1、定义类对象public class CAttributeFeature{ public string m_strAttributeName { get; set; } public double m_dAttributeFeature { get; set; } public CAttribu原创 2015-03-17 18:25:18 · 758 阅读 · 0 评论 -
C#中的委托、事件
转载自:http://blog.chinaunix.net/uid-576762-id-2733751.html 把C#中的委托(Delegate)和事件(Event)放到现在讲是有目的的:给下次写的设计模式——观察者(Observer)有一个参考。 委托和事件应该是C#相较于C++等之前的非托管的语言提出的一个新的术语(term)。“旧瓶装新酒”这样的描述似乎有转载 2015-03-25 11:11:42 · 665 阅读 · 0 评论 -
各种语言的时间戳转换
网上找了很多C#的时间戳转换,不知道那些人用不用过,反正,要不方法参数没有说明,要么根本就不对,说实话,在中国的技术博客里能找到解决问题的方法,还真是难。下面是在国外网站上找到的方法:链接如下:http://www.epochconverter.com/How to get the current epoch time in ...PHPtime() m原创 2015-04-18 17:03:46 · 3154 阅读 · 0 评论 -
计算机各种编码
转载自:http://blog.youkuaiyun.com/lvxiangan/article/details/8151670GBK,ISO-8859-1,GB2312的本质区别编码有几种 ,计算机最初是在美国等国家发明的 所以表示字符只有简单的几个字母只要对字母进行编码就好 我们标准码 iso-8859-1 这就是一个标准但是后来计算机普及了 于是就中国要使用计算机了 但是机器不认转载 2015-04-30 10:13:17 · 9134 阅读 · 0 评论 -
Unity C#单例模式
转载自:http://cl314413.blog.163.com/blog/static/190507976201442194813394/using UnityEngine; using System.Collections; public class MyClass : MonoBehaviour { private st转载 2015-05-13 11:42:37 · 648 阅读 · 0 评论 -
C#中in、out和ref的作用与区别
转载自:http://blog.youkuaiyun.com/jadeflute/article/details/5218627ref和out的区别在C# 中,既可以通过值也可以通过引用传递参数。通过引用传递参数允许函数成员更改参数的值,并保持该更改。若要通过引用传递参数, 可使用ref或out关键字。ref和out这两个关键字都能够提供相似的功效,其作用也很像C中的指针变量。它们的区别是:转载 2015-05-07 11:55:19 · 1052 阅读 · 0 评论 -
C#常用的集合类型(ArrayList类、Stack类、Queue类、Hashtable类、SortedList类)
转载自:http://www.cnblogs.com/linpengfeixgu/articles/1442980.html1.ArrayList类ArrayList类主要用于对一个数组中的元素进行各种处理。在ArrayList中主要使用Add、Remove、RemoveAt、Insert四个方法对栈进行操作。Add方法用于将对象添加到 ArrayList 的结尾处;Rem转载 2015-07-07 23:52:44 · 1218 阅读 · 0 评论