
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 33676 Articles for Programming

1K+ 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

6K+ 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

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

267 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

6K+ 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

2K+ 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]); } } } } }

649 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

939 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

1K+ 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

439 Views
To copy or clone a C# list, firstly set a list.List < string > myList = new List < string > (); myList.Add("One"); myList.Add("Two");Now declare a string array and use the CopyTo() method to copy.string[] arr = new string[10]; myList.CopyTo(arr);Let us see the complete code to copy a list into a one-dimensional array.Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List < string > myList = new List < string > (); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four"); ... Read More