文章分类 -  C#

C# 日期格式化Demo
摘要:DateTime dt = DateTime.Now; Console.WriteLine(dt.ToString("yyyy-MM-dd")); Console.WriteLine (string.Format ("{0:yyyy-MM-dd}",dt)); 阅读全文
posted @ 2011-12-01 14:42 tonylx 阅读(110) 评论(0) 推荐(0)
String Format for Int [C#]
摘要:String Format for Int [C#]2010-10-15 23:02Integer numbers can be formatted in .NET in many ways. You can use static method String.Format or instance method int.ToString. Following examples shows how to align numbers (with spaces or zeroes), how to format negative numbers or how to do custom formatti 阅读全文
posted @ 2011-12-01 14:32 tonylx 阅读(948) 评论(0) 推荐(0)
TODO
摘要:TODO:标记的注释,可以在任务列表中查看到.如果你有很多TODO(待办)可以查找起来又因为太多而麻烦,就写://TODO:xxxxxx在任务列表中双击就可以直接定位了. 阅读全文
posted @ 2011-08-23 11:28 tonylx 阅读(188) 评论(0) 推荐(0)
String Format for DateTime
摘要:String Format for DateTime [C#]This example shows how to formatDateTimeusingString.Formatmethod. All formatting can be done also usingDateTime.ToStringmethod.Custom DateTime FormattingThere are following custom format specifiersy(year),M(month),d(day),h(hour 12),H(hour 24),m(minute),s(second),f(sec. 阅读全文
posted @ 2011-08-18 11:28 tonylx 阅读(189) 评论(0) 推荐(0)
format C# 日期转换
摘要:string s = "2011-05-24T16:55:42"; DateTime dt = DateTime.Parse(s); string date = String.Format("{0:dd MMM yyyy 'at' hh:mm tt}", dt); 阅读全文
posted @ 2011-08-18 11:28 tonylx 阅读(142) 评论(0) 推荐(0)
The breakpoint will not currently be hit.
摘要:The breakpoint will not currently be hit.2009-07-07 10:211274人阅读评论(0)收藏举报vs2005无法进行单步调试:The breakpoint will not currently be hit. The source code is different from the original version昨天对dnn跟踪调试的时,设了断点后运行到断点处总提示“The breakpoint will not currently be hit. The source code is different from the origina. 阅读全文
posted @ 2011-08-09 10:12 tonylx 阅读(9769) 评论(1) 推荐(0)
时间的加减
摘要://DateTime d2 = DateTime.UtcNow.AddMinutes(-2); //System.Diagnostics.Debug.WriteLine(d2.ToString()); //System.Diagnostics.Debug.WriteLine(DateTime.UtcNow.ToString ()); DateTime d2 = DateTime.UtcNow; DateTime d3 = d2.Subtract(TimeSpan.FromMinutes(2)); System.Diagnostics.Debug.WriteLine(d2.ToString(). 阅读全文
posted @ 2011-07-21 11:18 tonylx 阅读(188) 评论(0) 推荐(0)
使用 TryParse 替代 Parse 提升转换效率
摘要:使用 TryParse 替代 Parse 提升转换效率2011年06月23日 星期四 17:09With the .NET Framework 2.0, there is a great number of improvements to the Base Class Library, one big improvement is that when you want to parse a string input into any other primitive value type(except Enum), you can use the TryParse instead of Par. 阅读全文
posted @ 2011-07-14 14:31 tonylx 阅读(622) 评论(0) 推荐(0)
C# #if DEBUG
摘要:#ifDEBUG首先,大小写不能写错,其次,解决方案配置设为:Debug,才会执行该语句,如果在条件里面搭配Debug.Assert等,效果甚佳。而如果要设置为Release模式,就不会执行条件语句中的内容,有时候可以通过设置!DEBUG来达到发布产品执行的代码。 示例代码:int debugNumber = 0;#if DEBUG Console.WriteLine("调试中的debugNumber: "+debugNumber);#endif#if !DEBUGdebugNumber++;Console.WriteLine("非调试中的debugNumber: 阅读全文
posted @ 2011-06-24 14:11 tonylx 阅读(31237) 评论(3) 推荐(1)
关于equal hashcode 重写,这样Remove方法可以正确使用
摘要:public static void Main(string[] args) { Product p1 = new Product{Id=1001}; Product p2 = new Product{Id=1002}; List<Product> list = new List<Product>(); list.Add(p1); list.Add(p2); Product p3 = new Product { Id = 1002 }; if (list.Contains(p3)) { list.Remove(p3); } Product p4 = new Produc 阅读全文
posted @ 2011-06-21 13:36 tonylx 阅读(480) 评论(0) 推荐(0)
c# ToString() 格式化字符串 、C# String.Format格式说明
摘要:转自:http://linglong117.blog.163.com/blog/static/2771454720091261436506/SpecifierTypeFormatOutput(PassedDouble 1.42)Output(PassedInt -12400)cCurrency{0:c}$1.42-$12,400dDecimal (Whole number){0:d}System.FormatException-12400eScientific{0:e}1.420000e+000-1.240000e+004fFixed point{0:f}1.42-12400.00gGener 阅读全文
posted @ 2011-06-21 10:43 tonylx 阅读(3437) 评论(0) 推荐(0)
C# format
摘要:转自:http://blog.csdn.net/ruanruoshi/archive/2010/02/22/5316425.aspxC#ToString()格式化收藏默认分类2010-01-12 13:46:34阅读24评论0字号:大中小C货币2.5.ToString("C")¥2.50D十进制数25.ToString("D5")00025E科学型25000.ToString("E")2.500000E+005F固定点25.ToString("F2")25.00G常规2.5.ToString("G&quo 阅读全文
posted @ 2011-06-21 10:39 tonylx 阅读(160) 评论(0) 推荐(0)
try... catch,try... finally
摘要:StreamReader reader=new StreamReader("myfile.txt");try{ int i = 5 / 0;}catch // No args, so it will catch any exception{}reader.Close();StreamReader reader=new StreamReader("myfile.txt");try{ int i = 5 / 0;}finally // Will execute despite any exception{ reader.Close();}The big di 阅读全文
posted @ 2011-06-17 18:03 tonylx 阅读(119) 评论(0) 推荐(0)
《Effective C#》Item 11:提倡使用foreach语句来进行循环操作
摘要:《Effective C#》Item 11:提倡使用foreach语句来进行循环操作http://www.21tx.com/2007年09月20日愚翁循环语句是编程的基本语句,在C#中除了沿用C语言的循环语句外,还提供了foreach语句来实现循环。那么我要说的就是,在循环操作中尽量使用foreach语句来实现。为了来更好地说明为什么要提倡使用foreach,用如下三种不同方式来编写循环语句。int[] nArray =newint[100];// Use "foreach" to loop arrayforeach(intiinnArray )Debug.WriteLin 阅读全文
posted @ 2011-06-14 16:12 tonylx 阅读(154) 评论(0) 推荐(0)
《Effective C#》Item 9:区别和认识四个判等函数
摘要:《Effective C#》Item 9:区别和认识四个判等函数http://www.21tx.com/2007年08月13日愚翁.net有四个判等函数?不少人看到这个标题,会对此感到怀疑。事实上确是如此,.Net提供了ReferenceEquals、静态Equals,具体类型的Equals以及==操作符这四个判等函数。但是这四个函数之间有细微的关系,改变其中一个函数的实现会影响到其他函数的操作结果。首先要说的是Object.ReferenceEquals和Object.Equals这两个静态函数,对于它们俩来说,是不需要进行重写的,因为它们已经完成它们所要得做的操作。对于Object.Re. 阅读全文
posted @ 2011-06-14 15:55 tonylx 阅读(276) 评论(0) 推荐(0)
《Effective C#》Item 8:确保“0”在值类型中是有效的
摘要:《Effective C#》Item 8:确保“0”在值类型中是有效的大家在看了这标题后,肯定会觉的,为什么要确保“0”是有效的,这一点主要是跟值类型的内存分配有关,值类型有默认的构造函数,这是没法避免的,因此值类型变量中的成员在初始化的时候所出现的细微问题(对于值类型这方面的知识可以参看我前面一篇文章)。http://blog.csdn.net/Knight94/archive/2006/07/01/861383.aspx日常中比较常见的两种值类型,一个是enum定义的枚举类型,一个是用struct定义的数据类型。那我接下来就分别说明这两种类型如果不定义“0”为一个有效值的所能造成的后果,. 阅读全文
posted @ 2011-06-14 14:41 tonylx 阅读(132) 评论(0) 推荐(0)
C# 位域[flags]
摘要:C# 位域[flags]收藏 .NET中的枚举我们一般有两种用法,一是表示唯一的元素序列,例如一周里的各天;还有就是用来表示多种复合的状态。这个时候一般需要为枚举加上[Flags]特性标记为位域,例如:[Flags]enumStyles{ShowBorder=1,//是否显示边框ShowCaption=2,//是否显示标题ShowToolbox=4//是否显示工具箱} 这样我们就可以用"或"运算符组合多个状态,例如myControl.Style=Styles.ShowBorder|Styles.ShowCaption; 这时myControl.Style枚举的值将变成 1+ 阅读全文
posted @ 2011-06-14 14:38 tonylx 阅读(244) 评论(0) 推荐(0)
System.Diagnostics命名空间里的Debug类和Trace类的用途(收藏)
摘要:System.Diagnostics命名空间里的Debug类和Trace类的用途(收藏)System.Diagnostics命名空间里的Debug类和Trace类的用途摘要在 .NET 类库中有一个 System.Diagnostics 命名空间,该命名空间提供了一些与系统进程、事件日志、和性能计数器进行交互的类库。当中包括了两个对开发人员而言十分有用的类——Debug类和Trace类。本文介绍了这两个类的一些基本用途,旨在提高广大开发人员的开发效率。目录使用Debug类来帮助调试Debug类和Trace类的区别使用Trace类来做程序日志小结参考资料使用Debug类来帮助调试调试程序对每个. 阅读全文
posted @ 2011-06-14 13:46 tonylx 阅读(130) 评论(0) 推荐(0)
C# 值类型转换推荐写法 demo
摘要://object objTest = 11; //int nValue = objTest as int; object o = 11; if (o is int) { int i = (int)o; Console.Write(i); }as 不能用于值类型, 要用is 加上前置转换代替,具体代码如上 阅读全文
posted @ 2011-06-14 13:27 tonylx 阅读(168) 评论(0) 推荐(0)
《Effective C#》Item 3:使用as和is操作符来做类型转换
摘要:《Effective C#》Item 3:使用as和is操作符来做类型转换在程序中,进行类型转换是常见的事。那么在C#中支持以前语言的类型转换方法,即用类型名进行强行转换,例如:objectobjTest =newNewType();NewType newValue = (NewType)objTest;但是这样转换,有个严重的问题,就是在把objTest强转换成NewType类型对象的时候,这个过程是不安全的,因此需要用try-catch语句来进行保护。这样一来,比较安全的代码方式应该如下所示。objectobjTest =newNewType();NewType newValue =nu. 阅读全文
posted @ 2011-06-14 13:16 tonylx 阅读(255) 评论(0) 推荐(0)