from http://dotnetperls.com/empty-string
Equality operator ==: 796 ms
string.Equals: 811 ms
string.IsNullOrEmpty: 312 ms
Length: 140 ms [fastest]
Instance Equals: 1077 ms
Using empty string methods
Here we see the five empty string tests shown in the graph and in the table above. Each of the five tests will be true, as the string str is empty. The code prints out the results of the tests, which you can see at the end.
=== Program that uses empty strings (C#) ===
class Program
{
static void Main()
{
// Example string
string str = "";
// Example tests
if (str == "")
{
// 1
// Test with op_Equality
System.Console.WriteLine(1);
}
if (string.Equals(str, ""))
{
// 2
// Test with static Equals method
System.Console.WriteLine(2);
}
if (string.IsNullOrEmpty(str))
{
// 3
// Test with IsNullOrEmpty
System.Console.WriteLine(3);
}
if (str.Length == 0)
{
// 4
// Test with Length property
System.Console.WriteLine(4);
}
if (str.Equals(""))
{
// 5
// Test with Equals method
System.Console.WriteLine(5);
}
}
}
Personal notes ~
2010年3月15日 星期一
訂閱:
文章 (Atom)
追蹤網誌清單
IT Info
Reference
標籤
- 代討論
- 防盜
- 常規表示式(regular expression)
- 進度
- 電子地圖
- 網站搬家程式
- Ajax Library
- Application of Perl
- C#
- CakePHP
- Coding Convention
- CSS
- Data injection
- DBI
- Debug
- Diff Browser
- Effect : Slideshow
- Engineering - Desing Pattern
- framework
- Framework - CodeIgniter
- Functions
- Imgick
- jquery
- JS Framework
- JS Library
- JS Object : Statement
- Linux
- Mapping Other Language
- Need to Turnning
- NetBeans
- OOAD-MVC
- open source suit software
- Performance
- Perl Installation
- PHP Class
- PHP rpc Java
- PHP to PERL
- Presentation
- RIA
- Serculity
- Service
- SQL injection
- Tips
- Tools
- Variable
- Versus
- WCF
- WebSite Thumbnail
- XML
- ZK Ajax