NenTang.vn
.NETLập trình căn bản C#
Chuỗi trong C#
Nhập môn Lập trình C#
Thời lượng: 55 phútĐọc khoảng: 4 phút
Danh mục hình và bảng
Từ viết tắt
Nội dung bài học không khai báo từ viết tắt bằng thẻ abbr.
Nội dung bài học
In C#, you can use strings as array of characters, However, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class.
When the above code is compiled and executed, it produces the following result −
When the above code is compiled and executed, it produces the following result −
When the above code is compiled and executed, it produces the following result −
When the above code is compiled and executed, it produces the following result −
When the above code is compiled and executed, it produces the following result −
Creating a String Object
You can create string object using one of the following methods −- By assigning a string literal to a String variable
- By using a String class constructor
- By using the string concatenation operator (+)
- By retrieving a property or calling a method that returns a string
- By calling a formatting method to convert a value or an object to its string representation
csharp
shellscript
Properties of the String Class
The String class has the following two properties −| Sr.No. | Property & Description |
|---|---|
| 1 | Chars Gets the Char object at a specified position in the current Stringobject. |
| 2 | Length Gets the number of characters in the current String object. |
Methods of the String Class
The String class has numerous methods that help you in working with the string objects. The following table provides some of the most commonly used methods − You can visit MSDN library for the complete list of methods and String class constructors.Examples
The following example demonstrates some of the methods mentioned above −Comparing Strings
csharp
shellscript
String Contains String
csharp
shellscript
Getting a Substring
csharp
csharp
Joining Strings
csharp
shellscript

