Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

String #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [Chaiyapat Tantiworachot](https://github.com/pixelart7)
- [Taha Bin Aziz](https://github.com/tahabinaziz)
49 changes: 49 additions & 0 deletions source/snippets/csharp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```