- 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 34494 Articles for Programming
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
313 Views
Let’s say our string is −var str = "welcome";Use the substring() method and the following, if you want to rotate only some characters. Here, we are rotating only 2 characters −var res = str.Substring(1, str.Length - 1) + str.Substring(0, 2);The following is the complete code −Example Live Demousing System; public class Program { public static void Main() { var str = "welcome"; Console.WriteLine("Original String = "+str); var res = str.Substring(1, str.Length - 1) + str.Substring(0, 2); Console.WriteLine("Rotating two characters in the String: "+res); } }OutputOriginal String = welcome Rotating two characters in the String: elcomewe
![radhakrishna](https://www.tutorialspoint.com/assets/profiles/13544/profile/60_40618-1512640354.jpg)
454 Views
To merge two sorted arrays, firstly set two sorted arrays −int[] array1 = { 1, 2 }; int[] array2 = { 3, 4 };Now, add it to a list and merge −var list = new List(); for (int i = 0; i < array1.Length; i++) { list.Add(array1[i]); list.Add(array2[i]); }Use the ToArray() method to convert back into an array −int[] array3 = list.ToArray();The following is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { int[] array1 = { 1, 2 }; int[] array2 ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
407 Views
Use the UnionWith method in C# to get the union of i.e. unique lements from two collections.Let’s say the following are our Dictionary −Dictionary < string, int > dict1 = new Dictionary < string, int > (); dict1.Add("pencil", 1); dict1.Add("pen", 2); Dictionary < string, int > dict2 = new Dictionary < string, int > (); dict2.Add("pen", 3);Now, use HashSet and UnionWith to get the union −HashSet < string > hSet = new HashSet < string > (dict1.Keys); hSet.UnionWith(dict2.Keys);The following is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
552 Views
The Union method gets the unique elements from both the lists.Let us set two lists −var list1 = new List{12, 65, 88, 45}; var list2 = new List{40, 34, 65};Now get the union of both the lists −var res = list1.Union(list2);The following is the example −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { // two lists var list1 = new List{12, 65, 88, 45}; var list2 = new List{40, 34, 65}; // finding union var res = list1.Union(list2); foreach(int i in res) { Console.WriteLine(i); } } }Output12 65 88 45 40 34
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
162 Views
To concat lists in C#, ue the Concat method.The following is the list −var list1 = new List{12, 40}; var list2 = new List{98, 122, 199, 230};Here is the Concat method −var res = list1.Concat(list2);The following is the example to work with Concat method −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { // two lists var list1 = new List{12, 40}; var list2 = new List{98, 122, 199, 230}; // concat var res = list1.Concat(list2); foreach(int i in res) { Console.WriteLine(i); } } }Output12 40 98 122 199 230
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
249 Views
Create more than one list −// two lists var list1 = new List{3, 4}; var list2 = new List{1, 2, 3};Now, use the Intersect() method to get the common values −var res = list1.Intersect(list2);The following is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { // two lists var list1 = new List{3, 4}; var list2 = new List{1, 2, 3}; // common values var res = list1.Intersect(list2); foreach(int i in res) { Console.WriteLine(i); } } }Output3
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
165 Views
Set three lists −// three lists var list1 = new List{3, 4}; var list2 = new List{1, 2, 3}; var list3 = new List{2, 5, 6};Now, use the Concat mthod to concat the above lists −var res1 = list1.Concat(list2); var res2 = res1.Concat(list3);Here is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { // three lists var list1 = new List{3, 4}; var list2 = new List{1, 2, 3}; var list3 = new List{2, 5, 6}; // concat var res1 = list1.Concat(list2); var res2 = res1.Concat(list3); foreach(int i in res2) { Console.WriteLine(i); } } }Output3 4 1 2 3 2 5 6
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
900 Views
Firstly, create lists −//three lists var list1 = new List{3, 4, 5}; var list2 = new List{1, 2, 3, 4, 5}; var list3 = new List{5, 6, 7, 8};Use the union method to get the union of list1 and list2 −var res1 = list1.Union(list2); var res2 = res1.Union(list3);The following is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { //three lists var list1 = new List{3, 4, 5}; var list2 = new List{1, 2, 3, 4, 5}; var list3 = new List{5, 6, 7, 8}; // finding union var res1 = list1.Union(list2); var res2 = res1.Union(list3); foreach(int i in res2) { Console.WriteLine(i); } } }Output3 4 5 1 2 6 7 8
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
507 Views
Firstly, set both the dictionaries −Dictionary < string, int > dict1 = new Dictionary < string, int > (); dict1.Add("water", 1); dict1.Add("food", 2); Dictionary < string, int > dict2 = new Dictionary < string, int > (); dict2.Add("clothing", 3); dict2.Add("shelter", 4);Now, create HashSet and use UnionsWith() method to find the union between the above two Dictionaries −HashSet < string > hSet = new HashSet < string > (dict1.Keys); hSet.UnionWith(dict2.Keys);The following is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { Dictionary < string, int > dict1 = ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Under anagram, another string would have the same characters present in the first string, but the order of characters can be different.Here, we are checking the following two strings −string str1 = "silent"; string str2 = "listen";Convert both the strings into character array −char[] ch1 = str1.ToLower().ToCharArray(); char[] ch2 = str2.ToLower().ToCharArray();Now, sort them −Array.Sort(ch1); Array.Sort(ch2);After sorting, convert them to strings −string val1 = new string(ch1); string val2 = new string(ch2);Compare both the strings for equality. If both are equal, that would mean they are anagrams.The following is the code −Example Live Demousing System; public class Demo { public static ... Read More