Concatenation
You can concatenate strings using the + operator or the String.Concat method.
string firstName = "devesh";
string lastName = "omar";
string fullName = firstName + " " + lastName; // "devesh omar
string fullNameConcat = String.Concat(firstName, " ", lastName); //
Interpolation
String interpolation is a more readable way to format strings.
string firstName = "devesh";
string lastName = "omar";
string fullName = $"{firstName} {lastName}"; // "devesh omar"
Format
The String.Format method provides a way to format strings.
string formatted = String.Format("Hello, {0} {1}!", firstName, lastName); // "Hello, devesh omar!"
Join
Combines multiple strings into one string with a specified separator.
string[] names = { "John", "Jane", "Doe" };
string joinedNames = String.Join(", ", names); // "John, Jane, Doe"
We will learn about
Contains
Determines if a substring exists within a string.
string sentence = "The quick brown fox";
bool containsQuick = sentence.Contains("quick"); // true
IndexOf
Finds the zero-based index of the first occurrence of a substring.
int index = sentence.IndexOf("quick"); // 4
LastIndexOf
Finds the zero-based index of the last occurrence of a substring.
string repeatedSentence = "The quick brown fox jumps over the lazy dog. The fox is quick.";
int lastIndex = repeatedSentence.LastIndexOf("quick"); // 49
Substring
Extracts a substring from a string starting at a specified index.
string substring = sentence.Substring(4, 5); // "quick"
Replace
Replaces all occurrences of a specified substring with another substring.
string modifiedSentence = sentence.Replace("quick", "slow"); // "The slow brown fox"
Remove
Deletes a specified number of characters starting at a particular index.
string removedPart = sentence.Remove(4, 6); // "The brown fox"
Insert
Inserts a string at a specified index.
string inserted = sentence.Insert(4, "very "); // "The very quick brown fox"
Concatenation
You can concatenate strings using the + operator or the String.Concat method.
string firstName = "devesh"; string lastName = "omar"; string fullName = firstName + " " + lastName; // "devesh omar string fullNameConcat = String.Concat(firstName, " ", lastName); //
Interpolation
String interpolation is a more readable way to format strings.
string firstName = "devesh"; string lastName = "omar"; string fullName = $"{firstName} {lastName}"; // "devesh omar"
Format
The String.Format method provides a way to format strings.
string formatted = String.Format("Hello, {0} {1}!", firstName, lastName); // "Hello, devesh omar!"
Join
Combines multiple strings into one string with a specified separator.
string[] names = { "John", "Jane", "Doe" }; string joinedNames = String.Join(", ", names); // "John, Jane, Doe"
We will learn about
Contains
Determines if a substring exists within a string.
string sentence = "The quick brown fox"; bool containsQuick = sentence.Contains("quick"); // true
IndexOf
Finds the zero-based index of the first occurrence of a substring.
int index = sentence.IndexOf("quick"); // 4
LastIndexOf
Finds the zero-based index of the last occurrence of a substring.
string repeatedSentence = "The quick brown fox jumps over the lazy dog. The fox is quick."; int lastIndex = repeatedSentence.LastIndexOf("quick"); // 49
Substring
Extracts a substring from a string starting at a specified index.
string substring = sentence.Substring(4, 5); // "quick"
Replace
Replaces all occurrences of a specified substring with another substring.
string modifiedSentence = sentence.Replace("quick", "slow"); // "The slow brown fox"
Remove
Deletes a specified number of characters starting at a particular index.
string removedPart = sentence.Remove(4, 6); // "The brown fox"
Insert
Inserts a string at a specified index.
string inserted = sentence.Insert(4, "very "); // "The very quick brown fox"
C# is primarily used on the Windows . NET framework, although it can be applied to an open source platform. This highly versatile programming language is an object-oriented programming language (OOP) and comparably new to the game, yet a reliable crowd pleaser.
The C# language is also easy to learn because by learning a small subset of the language you can immediately start to write useful code. More advanced features can be learnt as you become more proficient, but you are not forced to learn them to get up and running. C# is very good at encapsulating complexity.
The decision to opt for C# or Node. js largely hinges on the specific requirements of your project. If you're developing a CPU-intensive, enterprise-level application where stability and comprehensive tooling are crucial, C# might be your best bet.
C# is part of .NET, a free and open source development platform for building apps that run on Windows, macOS, Linux, iOS, and Android. There's an active community answering questions, producing samples, writing tutorials, authoring books, and more.
Copyrights © 2024 letsupdateskills All rights reserved