C# How To's
C# How To's
These examples show how to solve common tasks in C#. Each page has a short code example and an explanation.
Numbers
- Add Two Numbers - Add two numbers and print the result.
- Swap Two Variables - Exchange the values of two variables.
- Even or Odd Number - Check if a number is even or odd.
- Positive or Negative - Check if a number is positive, negative or zero.
- Reverse a Number - Reverse the digits of a number.
- Sum of Digits - Add up the digits of a number.
- Square Root - Find the square root of a number.
- Area of Rectangle - Calculate the area of a rectangle.
- Celsius to Fahrenheit - Convert a temperature from Celsius to Fahrenheit.
- Random Number - Generate a random number.
Strings
- Count Words - Count how many words are in a sentence.
- Count Vowels - Count how many vowels are in a string.
- Reverse a String - Reverse the characters in a string.
- Palindrome Check - Check if a word is the same forward and backward.
- Check Anagram - Check if two words have the same letters in a different order.
- Split a String - Split a string into words, or at a separator like a comma.
- Remove Whitespace - Remove spaces from the start, the end, or all of a string.
- Count Character Frequency - Count how many times each character appears in a string.
Arrays
- Sum of Array Elements - Add all the elements in an array.
- Find Array Average - Calculate the average value of the elements in an array.
- Sort an Array - Sort the elements of an array, from low to high or high to low.
- Min and Max in Array - Find the lowest and the highest value in an array.
- Merge Two Arrays - Combine two arrays into one.
- Remove Duplicates - Remove duplicate values from an array.
Algorithms
- Factorial of a Number - Calculate the factorial of a number.
- Fibonacci Sequence - Print the first numbers of the Fibonacci sequence.
- Find GCD - Find the greatest common divisor of two numbers.
- Check Prime Number - Check if a number is a prime number.
Loops
- Loop Through a List - Loop through all the items in a List.
- Loop Through a Dictionary - Loop through all the keys and values of a Dictionary.