From 4bc983d74fc1a8940f4cd60f7b58c9ce24543d0b Mon Sep 17 00:00:00 2001 From: tahabinaziz Date: Sat, 31 Oct 2020 00:20:19 +0500 Subject: [PATCH] String --- CONTRIBUTORS.md | 3 +- source/snippets/csharp/index.md | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 28fe9ba..bd565c8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -40,4 +40,5 @@ - [Rabin Khatiwada](https://github.com/rabinkhatiwada) - [Adrian Hernandez-Lopez](https://github.com/AdrianHL) - [Juan Benitez](https://github.com/juanbenitez) -- [Chaiyapat Tantiworachot](https://github.com/pixelart7) \ No newline at end of file +- [Chaiyapat Tantiworachot](https://github.com/pixelart7) +- [Taha Bin Aziz](https://github.com/tahabinaziz) \ No newline at end of file diff --git a/source/snippets/csharp/index.md b/source/snippets/csharp/index.md index b06406f..bbc6fad 100644 --- a/source/snippets/csharp/index.md +++ b/source/snippets/csharp/index.md @@ -25,3 +25,52 @@ private void Shuffle(string[] e) } } ``` + +# C# + +## C# Strings + +Strings are used for storing text. + +```csharp +string greeting = "Hello"; +``` + +## String Length + +A string in C# is actually an object, which contain properties and methods that can perform certain operations on strings. For example, the length of a string can be found with the Length property: + +```csharp +string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +Console.WriteLine("The length of the txt string is: " + txt.Length); +``` + +## Other Methods + +There are many string methods available, for example ToUpper() and ToLower(), which returns a copy of the string converted to uppercase or lowercase: + +```csharp +string txt = "Hello World"; +Console.WriteLine(txt.ToUpper()); // Outputs "HELLO WORLD" +Console.WriteLine(txt.ToLower()); // Outputs "hello world" +``` + +## String Concatenation + +The + operator can be used between strings to combine them. This is called concatenation: + +```csharp +string firstName = "John "; +string lastName = "Doe"; +string name = firstName + lastName; +Console.WriteLine(name); +``` + +You can also use the string.Concat() method to concatenate two strings: + +```csharp +string firstName = "John "; +string lastName = "Doe"; +string name = string.Concat(firstName, lastName); +Console.WriteLine(name); +```