string Type क्या है
एक string text का एक टुकड़ा है, जैसे किसी name tag या किसी ribbon पर लिखा एक वाक्य। एक बार बनने के बाद, string को जगह पर edit नहीं किया जा सकता, इसलिए इसे बदलना असल में एक नई string बनाता है।
In this page:
Syntax
string variableName = "text";
string joined = first + " " + second;
string interpolated = $"Hello, {variableName}!";
The string Type
एक string characters का एक immutable sequence है, जो double quotes से लिखा जाता है। Strings + से concatenation, $"..." से interpolation, और बहुत सारे built-in methods को support करते हैं।
चूंकि strings immutable हैं, हर "modification" असल में एक नई string बनाती है।
Note:
readability के लिए concatenation पर string interpolation (
$"Hello {name}") को प्राथमिकता दें।उदाहरण: The string Type
using System;
class Program
{
static void Main(string[] args)
{
string first = "Ada";
string last = "Lovelace";
string full = first + " " + last;
string greeting = $"Hello, {full}!";
Console.WriteLine(full);
Console.WriteLine(greeting);
Console.WriteLine(full.Length);
Console.WriteLine(full.ToUpper());
}
}
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- strings को गलत case से compare करना और equality की उम्मीद करना, क्योंकि
"a" == "A"false है। - यह उम्मीद करना कि
s.ToUpper()sको बदल देगा, जबकि strings immutable हैं और method एक नई string return करता है। - loop में
+से एक लंबी string बनाना, जो कई temporary strings बनाता है;StringBuilderका उपयोग करें।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: