string msg = "Hello, World!"; Console.WriteLine(msg); //Output "Hello, World!" char[] letters = { 'H', 'e', 'l', 'l', 'o' }; string greeting = new string(letters); Console.WriteLine(greeting); //Output "Hello"
string fullName = "Estudy" + " " + "247"; Console.WriteLine(fullName); //Output "Estudy 247" int index = fullName.IndexOf("247"); Console.WriteLine(index); //Output "7" string[] names = fullName.Split(' '); Console.WriteLine(names[0]); //Output "Estudy"
string filePath = @"C:\Users\Estudy\Documents"; Console.WriteLine(filePath); string multiLineString = @"This is a multi-line string."; Console.WriteLine(multiLineString);
string website = "Estudy247"; string greeting = $"Hello, {website}!"; Console.WriteLine(greeting); //Output "Hello, Estudy247!"
Strings in programming languages are considered immutable. This means that once a string is created, its contents cannot be changed. As a result, operations like concatenation can be time-consuming if done repeatedly in a loop. To avoid such inefficiencies, it’s recommended to use the StringBuilder class instead. StringBuilder is a mutable class that provides an efficient way to append, insert, or remove characters from a string.
