Strings
$ se prefix ki hui string ek interpolated string hoti hai — {braces} ke andar ke expressions evaluate hoke directly insert ho jate hain, jo usually + se string banane se zyada clear hota hai.
Main.cs
Khud try karo →using System;
class Program {
static void Main() {
string name = "world";
string greeting = $"Hello, {name}!";
Console.WriteLine(greeting);
Console.WriteLine(greeting.Length);
}
}Output
Hello, world! 13
== actually content compare karta hai
Java ke ulat, jahan strings par == object references compare karta hai aur content compare karne ke liye .equals() chahiye hota hai, C# ka == operator string ke liye overloaded hai taki wo directly content compare kare — alag-alag completely bani do strings bhi equal compare hoti hain agar unke characters match karte hon.
Main.cs
Khud try karo →using System;
class Program {
static void Main() {
string a = "hello";
string b = "hel" + "lo";
Console.WriteLine(a == b);
}
}Output
True
Aage: classes aur objects — ek class, fields, aur constructors define karna.
Practice exercise
string name = "Rust" diya gaya hai, string interpolation use karke "Learning Rust today" print karo.