- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2628 Articles for Csharp
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
147 Views
The following is our integer array −int[] myArr = new int[6] { 8, 4, 2, 5, 9, 14 };Firstly, get the length of the array, and loop through the array to find the sum of the elements. After that, divide it with the length.int len = myArr.Length; int sum = 0; int average = 0; for (int i = 0; i < len; i++) { sum += myArr[i]; } average = sum / len;Here is the complete codeExample Live Demousing System; public class Program { public static void Main() { ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
939 Views
Use the Replace() method to replace a character with asterisks.Let’s say our string is −string str = "dem* text";To replace it, use the Replace() method −str.Replace('*', 'o');Here is the complete code −Example Live Demousing System; public class Program { public static void Main() { string str = "dem* text"; Console.WriteLine("Initial string = " + str); string res = str.Replace('*', 'o'); // after replacing Console.WriteLine("After replacing asterisk = " + res.ToString()); } }OutputInitial string = dem* text After replacing asterisk = demo text
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
5K+ Views
Let’s say our string is −string str = "abcd$ef$gh";To replace the special character, use the Replace() method.string res = str.Replace('$', 'k');The following is the complete code to replace character from a string −Example Live Demousing System; public class Program { public static void Main() { string str = "abcd$ef$gh"; Console.WriteLine("Initial string = " + str); string res = str.Replace('$', 'k'); // after replacing Console.WriteLine("Replaced string = " + res.ToString()); } }OutputInitial string = abcd$ef$gh Replaced string = abcdkefkgh
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
Set a string with duplicate words.string str = "One Two Three One";Above, you can see the word “One” comes twice.To remove dulicate words, you can try to run the following code in C# −Example Live Demousing System; using System.Linq; public class Program { public static void Main() { string str = "One Two Three One"; string[] arr = str.Split(' '); Console.WriteLine(str); var a = from k in arr orderby k select k; Console.WriteLine("After removing duplicate words..."); ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
168 Views
Firstly, declare a HashSet and add elements −var names = new HashSet(); names.Add("Tim"); names.Add("John"); names.Add("Tom"); names.Add("Kevin");To remove an element, use RemoveWhere.names.RemoveWhere(x => x == "John");Let us see the complete example −Exampleusing System; using System.Collections.Generic; public class Program { public static void Main() { var names = new HashSet < string > (); names.Add("Tim"); names.Add("John"); names.Add("Tom"); names.Add("Kevin"); Console.WriteLine("Initial Set..."); foreach(var val in names) { Console.WriteLine(val); } names.RemoveWhere(x => x ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
5K+ Views
Set the list.List < int > list = new List < int > (); list.Add(99); list.Add(49); list.Add(32);To get unique elements.List myList = list.Distinct().ToList();Here is the complete example to display unique values from a list.Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List < int > list = new List < int > (); list.Add(55); list.Add(45); list.Add(55); list.Add(65); list.Add(73); list.Add(24); list.Add(65); Console.WriteLine("Initial List..."); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
Let’s say you need to find the elements in the following list to be greater than 80.int[] arr = new int[] {55, 100, 87, 45};For that, loop until the array length. Here, res = 80 i.e. the given element.for (int i = 0; i < arr.Length; i++) { if(arr[i] res) { Console.WriteLine(arr[i]); } } } } }
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
471 Views
Declare a list and add elements.List list = new List(); list.Add(50); list.Add(90); list.Add(50); list.Add(100);Now, use Distinct() method to get the unique elements only.List myList = list.Distinct().ToList();The following is the complete code to remove duplicate elements from a List −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List < int > list = new List < int > (); list.Add(50); list.Add(90); list.Add(50); list.Add(100); Console.WriteLine("Initial List..."); foreach(int a in list) ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
669 Views
Set the first list.int[] arr1 = { 65, 57, 63, 98 };Now, set the second list.int[] arr2 = { 43, 65, 33, 57 };Let us now see the complete code to check if two lists have common elements using == and < operators.Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { int[] arr1 = { 65, 57, 63, 98 }; ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
961 Views
Firstly, declare and initialize a jagged array.int[][] arr = new int[][] { new int[] { 0, 0 }, new int[] { 1, 2 }, new int[] { 2, 4 }, new int[] { 3, 6 }, new int[] { 4, 8 } };Now use the length property to get the length.arr.LengthThe following is the complete code −Example Live Demousing System; public class Program { public static void Main() { int[][] arr = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }, new int[]{ 4, 8 } }; // Length Console.WriteLine("Length:"+arr.Length); Console.WriteLine("Upper Bound: {0}",arr.GetUpperBound(0).ToString()); Console.WriteLine("Lower Bound: {0}",arr.GetLowerBound(0).ToString()); Console.WriteLine("Dimensions of Array : " + arr.Rank); } }OutputLength:5 Upper Bound: 4 Lower Bound: 0 Dimensions of Array : 1