Chandu yadav has Published 1091 Articles

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

Chandu yadav

Chandu yadav

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

123 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

279 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

132 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

399 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

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

What will happen to MySQL current transaction, if in the middle of that transaction, the DDL statement is executed?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 11:30:35

326 Views

The current MySQL transaction will be committed and ended when any of the DDL statement such as CREATE or DROP databases, Create, ALTER or DROP tables or stored routines is executed in the middle of the current transaction. All the database changes made in the current transaction will be made ... Read More

How to clone a generic list in C#?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 11:02:47

507 Views

A list is a Generic collection to hold elements of same datatypes.To clone a list, you can use the CopyTo method.Declare a list and add elements −List < string > myList = new List < string > (); myList.Add("Programming"); myList.Add("Web Dev"); myList.Add("Database");Now create a new array and clone the list ... Read More

C# program to merge two Dictionaries

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 10:52:52

2K+ Views

Set the two dictionaries −Dictionary < string, int > dict1 = new Dictionary < string, int > (); dict1.Add("laptop", 1); dict1.Add("desktop", 2); Dictionary < string, int > dict2 = new Dictionary < string, int > (); dict2.Add("desktop", 3); dict2.Add("tablet", 4); dict2.Add("mobile", 5);Now use HashSet and UnionWith() method to merge the ... Read More

Thread Synchronization in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 10:15:44

671 Views

Synchronize access to resources in multithreaded applications using Synchronization.Mutex to Synchronize ThreadsA mutex can be used to synchronize threads across processes. Use it to prevent the simultaneous execution of a block of code by more than one thread at a time.C# lock statement is used to ensure that a block ... Read More

Advertisements