- 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 34488 Articles for Programming
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
250 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)
904 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
298 Views
Heterogram for a string means the string isn’t having duplicate letters. For example −Mobile Cry LaptopLoop through each word of the string until the length of the string −for (int i = 0; i < len; i++) { if (val[str[i] - 'a'] == 0) val[str[i] - 'a'] = 1; else return false; }Above, len is the length of the string.Let us see the complete code −Example Live Demousing System; public class GFG { static bool checkHeterogram(string str, int len) { int []val = new int[26]; for (int i ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Firstly, set the Hex String −string str = "7D";Now, use the Convert.ToSByte() method to convert the Hex string to Hex number −Console.WriteLine(Convert.ToSByte(str, 16));Let us see the complete code −Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { string str = "7D"; Console.WriteLine(Convert.ToSByte(str, 16)); } } }Output125Another way of converting Hex String to Hex Number −Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { string str = "7D"; Console.WriteLine(Convert.ToInt32(str, 16)); } } }Output125
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
739 Views
Firstly, set a tuple −Tuple t = Tuple.Create(99,53);Now, convert the tuple to an array −int[] arr = new int[]{t.Item1, t.Item2};The following is the code to convert a tuple into an array −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { Tuple t = Tuple.Create(99,53); int[] arr = new int[]{t.Item1, t.Item2}; foreach (int val in arr) { Console.WriteLine(val); } } } }Output99 53
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
365 Views
To get the binary of Decimal, using recursion, firstly set the decimal number −int dec = 30;Now pass the value to a function −public int displayBinary(int dec) { }Now, check the condition until the decimal value is 0 and using recursion get the mod 2 of the decimal num as shown below. The recursive call will call the function again with the dec/2 value −public int displayBinary(int dec) { int res; if (dec != 0) { res = (dec % 2) + 10 * displayBinary(dec / 2); Console.Write(res); return ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
192 Views
To merge two sorted arrays into a list, firstly set two sorted arrays −int[] array1 = { 1, 2 }; int[] array2 = { 3, 4 };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]); }Now, use the ToArray() method to convert back into an array as shown below −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { int[] array1 = { 56, 70, 77}; int[] array2 = ... Read More