Chandu yadav has Published 1163 Articles

UnionWith Method in C#

Chandu yadav

Chandu yadav

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

406 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 ... Read More

C# program to find Union of two or more Dictionaries

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 13:01:54

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 ... Read More

C# program to concat two or more Lists

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 13:00:54

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; ... Read More

How to check the Existence of a File using C#?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 12:45:42

69 Views

Let’s say we need to find the following file −E:ew.txtTo check the existence of the above file, use the Exists() method −if (File.Exists(@"E:ew.txt")) {    Console.WriteLine("File exists..."); }Here is the complete code to check the existence of a file −Example Live Demousing System; using System.IO; public class Demo {   ... Read More

Different ways of Reading a file in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 12:43:05

219 Views

Here, we are reading two different files −Reading text file −Example Live Demousing System; using System.IO; namespace FileApplication {    class Program {       static void Main(string[] args) {          try {             using (StreamReader sr = new StreamReader("d:/new.txt")) { ... Read More

How to inherit a class in C#?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 12:36:17

103 Views

Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application.When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing ... Read More

How to iterate over a C# tuple?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 12:28:17

2K+ Views

Firstly, declare a tuple and add values −Tuple tuple = new Tuple(100, "Tom");With C#, to iterate over a tuple, you can go for individual elements −tuple.Item1 // first item tuple.Item2 // second item To display the complete tuple, just use: // display entire tuple Console.WriteLine(tuple);Let us see the complete ... Read More

How to initialize a rectangular array in C#?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 12:23:31

261 Views

An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations.Multi-dimensional arrays are also called rectangular array. Multidimensional arrays are initialized by specifying bracketed values for ... Read More

How to insert an item in a list at a given position in C#?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 12:19:34

2K+ Views

To insert an item in an already created List, use the Insert() method.Firstly, set elements −List list = new List(); list.Add(989); list.Add(345); list.Add(654); list.Add(876); list.Add(234); list.Add(909);Now, let’s say you need to insert an item at 4th position. For that, use the Insert() method −// inserting element at 4th position ... Read More

In which order MySQL will invoke the triggers if we created multiple triggers of same event and action time?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 12:13:23

200 Views

In this case, MySQL will invoke the triggers in the order in which they are created. But with the help of following options, we can change the order −FOLLOWS optionThis option allows the new trigger to activate after the existing trigger.SyntaxFOR EACH ROW FOLLOWS trigger_namePRECEDES optionThis option allows the new ... Read More

Advertisements