
C# using的三种方式
using指令 引用命名空间,以减少输入。这也是我们最常用的地方。 如 using System.Text; using别名 http://cppkey.com/archives/2034 &nbRead More →
using指令 引用命名空间,以减少输入。这也是我们最常用的地方。 如 using System.Text; using别名 http://cppkey.com/archives/2034 &nbRead More →
问题 在C# using的时候,我们可能经常有一系列长长的名字 比如我引入protobuf-net用于使用的时候,要使用它必须使用一个长长的
1 2 3 4 5 6 |
//使用protobuff消息结构 using global::ProtoBuf.IExtensible; //或者当参数的时候 private delegate void PacketProcessFuc(global::ProtoBuf.IExtensible packet); |
看见百度出来的一埣垃圾真蛋疼。 将文件夹A全部拷贝到文件夹B。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//拷贝文件夹 public static void dirCopy(string SourcePath, string DestinationPath) { //拷贝所有文件夹 foreach (string dirPath in Directory.GetDirectories(SourcePath, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath)); } //拷贝文件并且替换掉同名的文件 foreach (string newPath in Directory.GetFiles(SourcePath, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true); } } |
endRead More →
在C#语言中进行类型转换的操作符is和as。is和as都是强制类型转换,但这两者有什么相同之处和不同之处呢?在使用is和as需要注意哪些事项?下面我们从简单的代码示例去探讨这个简单的问题。注:此博文只是本人学习Read More →
定义string变量为str,内存流变量为ms,比特数组为bt 1.字符串=>比特数组
1 2 3 4 5 6 7 8 9 10 |
(1)byte[] bt=System.Text.Encoding.Default.GetBytes("字符串"); (2)byte[] bt=Convert.FromBase64String("字符串");//补充: System.Text.Encoding.Unicode.GetBytes(str); System.Text.Encoding.UTF8.GetBytes(str); System.Text.Encoding.GetEncoding("gb2312").GetBytes(str); //指定编码方式string str = "中国?ss123?"; byte[] bytes = System.Text.Encoding.Default.GetBytes(str); //gb2312编码 汉字占2个字节、英文字母占1个字节 bytes长度为12 string s = System.Text.Encoding.Default.GetString(new byte[] { bytes[0],bytes[1] });//解码后为“中”byte[] bytes = {97, 98, 99, 100, 101, 102}; string str = System.Text.Encoding.ASCII.GetString(bytes); //结果为:abcdef |
[crayon-5c6d0b1cb8c837450Read More →
问题 利用protobuf-net的protogen生成消息后,发的时候没有问题,但在收的时候却总是得到的数据为空,一直纳闷是为什么。 在百度(找了n篇文章,全是一个抄一个一个抄一个,百度不死, 中国不富)后,Read More →
转载 sealed关键字: sealed的中文意思是密封,故名思义,就是由它修饰的类或方法将不能被继承或是重写。 在类声明中使用sealed可防止其它类继承此类;在方法声明中使用sealed修饰符Read More →
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<font face="Consolas">bool -> System.Boolean (布尔型,其值为 true 或者 false) byte -> System.Byte (字节型,占 1 字节,表示 8 位正整数,范围 0 ~ 255) sbyte -> System.SByte (带符号字节型,占 1 字节,表示 8 位整数,范围 -128 ~ 127) char -> System.Char (字符型,占有两个字节,表示 1 个 Unicode 字符) short -> System.Int16 (短整型,占 2 字节,表示 16 位整数,范围 -32,768 ~ 32,767) ushort -> System.UInt16 (无符号短整型,占 2 字节,表示 16 位正整数,范围 0 ~ 65,535) uint -> System.UInt32 (无符号整型,占 4 字节,表示 32 位正整数,范围 0 ~ 4,294,967,295) int -> System.Int32 (整型,占 4 字节,表示 32 位整数,范围 -2,147,483,648 到 2,147,483,647) float -> System.Single (单精度浮点型,占 4 个字节) ulong -> System.UInt64 (无符号长整型,占 8 字节,表示 64 位正整数,范围 0 ~ 大约 10 的 20 次方) long -> System.Int64 (长整型,占 8 字节,表示 64 位整数,范围大约 -(10 的 19) 次方 到 10 的 19 次方) double -> System.Double (双精度浮点型,占8 个字节) </font> |
Linux下IDE就是个悲剧,安装了Anjuta,但有这个提示,肯定就是glib。 Ubuntu环境解决办法:
1 |
sudo apt-get install libglib2.0-dev pkg-config |
OK~Read More →
Designed using Responsive Brix WordPress Theme. Powered by WordPress.