← Back to C# Course | Chapter 2: Variables & Types | Lesson 5 of 7

string Type क्या है

एक string text का एक टुकड़ा है, जैसे किसी name tag या किसी ribbon पर लिखा एक वाक्य। एक बार बनने के बाद, string को जगह पर edit नहीं किया जा सकता, इसलिए इसे बदलना असल में एक नई string बनाता है।

In this page:

  1. The string Type
Syntax
csharp
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

markup
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());
    }
}
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. #}
आम गलतियां
  1. strings को गलत case से compare करना और equality की उम्मीद करना, क्योंकि "a" == "A" false है।
  2. यह उम्मीद करना कि s.ToUpper() s को बदल देगा, जबकि strings immutable हैं और method एक नई string return करता है।
  3. loop में + से एक लंबी string बनाना, जो कई temporary strings बनाता है; StringBuilder का उपयोग करें।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.