C# String Theory—String fields and properties
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:Articles |
| C# Articles |
| edit |
Contents |
[edit]
String fields and properties
The String class has one public field and two properties which you will find useful.
[edit]
Empty field
String.Empty is a read-only field which represents the empty string. The value of Empty is the zero-length string, i.e., "".
string teststring = null; if (teststring != null) { return teststring; } return String.Empty;
[edit]
Chars property
The Chars accessor returns the character at a specified character position in the instance. This property is the indexer for the String class. The index parameter is zero-based.
string hexString = "C0C0BABE"; for (int i = 0; i < hexString.Length; i ++) { Console.Write (hexString[i]); // indexer }
Note: a Unicode character may be represented by more than one Char. In such a case, use the System.Globalization.StringInfo class to work with each individual Unicode character instead of each Char.
[edit]
Length property
Length property returns the number of characters in this instance.
Console.WriteLine ( ("The length of a film should be directly" + " related to the endurance of the human bladder.").Length ); // "86"
|

