string कीवर्ड System.String क्लास का एक उपनाम है। String क्लास में निम्नलिखित दो प्रॉपर्टीज हैं:
| क्र.सं. | प्रॉपर्टी और विवरण |
|---|---|
| 1 | Chars वर्तमान String ऑब्जेक्ट में निर्दिष्ट स्थिति पर Char ऑब्जेक्ट प्राप्त करता है। |
| 2 | Length वर्तमान String ऑब्जेक्ट में कैरेक्टर्स की संख्या प्राप्त करता है। |
String क्लास के कुछ मेथड्स निम्नलिखित हैं:
| क्र.सं. | मेथड्स और विवरण |
|---|---|
| 1 | public static int Compare(string strA, string strB) दो निर्दिष्ट स्ट्रिंग ऑब्जेक्ट्स की तुलना करता है और एक इंटीजर लौटाता है जो क्रम में उनकी सापेक्ष स्थिति को दर्शाता है। |
| 2 | public static int Compare(string strA, string strB, bool ignoreCase) दो निर्दिष्ट स्ट्रिंग ऑब्जेक्ट्स की तुलना करता है और एक इंटीजर लौटाता है जो क्रम में उनकी सापेक्ष स्थिति को दर्शाता है। हालांकि, यदि बूलियन पैरामीटर true है तो केस को अनदेखा करता है। |
| 3 | public static string Concat(string str0, string str1) दो स्ट्रिंग ऑब्जेक्ट्स को जोड़ता है। |
| 4 | public static string Concat(string str0, string str1, string str2) तीन स्ट्रिंग ऑब्जेक्ट्स को जोड़ता है। |
| 5 | public static string Concat(string str0, string str1, string str2, string str3) चार स्ट्रिंग ऑब्जेक्ट्स को जोड़ता है। |
आइए देखें कि स्ट्रिंग कैसे बनाएं और निम्नलिखित उदाहरण में स्ट्रिंग को कैसे जोड़ें:
उदाहरण
using System; namespace StringApplication { class StringProg { static void Main(string[] args) { string[] starray = new string[]{"Cricket is my life", "It is played between two teams", "It has three formats", "T20, Test Cricket and ODI", "Cricket is life" }; string str = String.Join("\n", starray); Console.WriteLine(str); } } }