UnionWith Method in C#

Chandu yadav
Updated on 22-Jun-2020 13:09:51

708 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

Create MySQL Views Without Any Column List

Samual Sam
Updated on 22-Jun-2020 13:09:29

185 Views

While creating a view, providing the list of columns is optional. The following example will illustrate by creating the views without any column list −mysql> Select * from student_detail; +-----------+-------------+------------+ | Studentid | StudentName | address    | +-----------+-------------+------------+ |       100 | Gaurav      | Delhi      | |       101 | Raman       | Shimla     | |       103 | Rahul       | Jaipur     | |       104 | Ram         | Chandigarh | |     ... Read More

Merge Two Sorted Arrays in C#

radhakrishna
Updated on 22-Jun-2020 13:09:18

862 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

String Slicing in C# to Rotate a String

George John
Updated on 22-Jun-2020 13:08:40

484 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

String Formatting in C# to Add Padding

seetha
Updated on 22-Jun-2020 13:08:09

1K+ Views

With C#, you can easily format content and add padding to it.To add padding −const string format = "{0,-5} {1,5}";Now, add the padding to the strings −string str1 = string.Format(format, "Rank","Student"); string str2 = string.Format(format, "2","Tom");Let us see the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program {    public static void Main() {       // set padding       const string format = "{0,-5} {1,5}";       string str1 = string.Format(format, "Rank","Student");       string str2 = string.Format(format, "2","Tom");       Console.WriteLine(str1);       Console.WriteLine(str2);    } }OutputRank Student 2 Tom

Create MySQL View Based on Another Existing View

George John
Updated on 22-Jun-2020 13:07:56

488 Views

In MySQL, we can create a view that is based on another existing view. To make it understand we are having the view ‘Info’ with the following data −mysql> Create view info AS Select Id, Name, Subject FROM student_info; Query OK, 0 rows affected (0.11 sec) mysql> Select * from Info; +------+---------+------------+ | Id | Name | Subject | +------+---------+------------+ | 101 | YashPal | History | | 105 | Gaurav | Literature | | 125 | Raman | Computers | | NULL | Ram | Computers | +------+---------+------------+ 4 rows in set (0.00 sec)Now, with the help of ... Read More

String Formatting in C# to Add Padding on the Right

vanithasree
Updated on 22-Jun-2020 13:07:37

289 Views

To add padding on the right to a string −const string format = "{0,10}";Now add it to the string −string str1 = string.Format(format, "Marks","Subject");Let us see the complete code −Example Live Demousing System; public class Program {    public static void Main() {       // set right padding       const string format = "{0,10}";       string str1 = string.Format(format, "Marks","Subject");       string str2 = string.Format(format, "95","Maths");       Console.WriteLine(str1);       Console.WriteLine(str2);    } }OutputMarks 95

Delete MySQL Temporary Table

V Jyothi
Updated on 22-Jun-2020 13:07:23

647 Views

As we know that MySQL temporary table would be deleted if the current session is terminated. But of still in between the session we want to delete the temporary table than with the help of the DROP statement we can delete the temporary table. It can be understood with the help of the following example −ExampleIn this example, we are deleting the temporary table named ‘SalesSummary’ −mysql> DROP TABLE SalesSummary; Query OK, 0 rows affected (0.00 sec)The above query will delete the table and it can be confirmed from the query below −mysql> Select * from SalesSummary; ERROR 1146 (42S02): ... Read More

Swapping Characters of a String in C#

Arjun Thakur
Updated on 22-Jun-2020 13:06:49

2K+ Views

To swap characters of a string, use the Select method.Firstly, let’s say our string is −string str = "PQRQP";Now, you need to swap every occurrence of P with Q and Q with P −str.Select(a=> a == 'P' ? 'Q' : (a=='Q' ? 'P' : a)).ToArray();The above replaces the characters.Let us see the compelet code −Example Live Demousing System; using System.Linq; public class Program {    public static void Main() {       string str = "PQRQP";       var res= str.Select(a=> a == 'P' ? 'Q' : (a=='Q' ? 'P' : a)).ToArray();       str = new String(res);       Console.WriteLine(str);    } }OutputQPRPQ

Create MySQL Views with Column List

Anjana
Updated on 22-Jun-2020 13:06:25

266 Views

As we know that while creating a view, providing the list of columns is optional. But if we are providing the name of the columns while creating the view then the number of names in the list of columns must be the same as the number of columns retrieved by the SELECT statement.ExampleThe following example will illustrate by creating the views with column list −mysql> Select * from student_detail; +-----------+-------------+------------+ | Studentid | StudentName | address    | +-----------+-------------+------------+ | 100       | Gaurav      | Delhi      | | 101       | Raman ... Read More

Advertisements