Arjun Thakur has Published 1025 Articles

Default value of StringBuilder in C#

Arjun Thakur

Arjun Thakur

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

569 Views

Use the default operator to get the default value of StringBuilder.StringBuilder str = default(StringBuilder);Above, we have used the default keywords to get the default value.Let us see the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       StringBuilder ... Read More

How can we get the structure of a MySQL view as we can get the structure of a MySQL table?

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 13:41:44

446 Views

As we know that views are a type of virtual tables and are a composition of tables too hence we can use the same query to get the structure of a view which we use to get the structure of a table. In other words, we can use DESCRIBE statement to get ... Read More

Swapping Characters of a String in C#

Arjun Thakur

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

C# program to find Union of two or more Lists

Arjun Thakur

Arjun Thakur

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

1K+ 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 ... Read More

Union Method in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 12:59:22

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

What are the prerequisites before starting writing and using MySQL views?

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 12:56:03

240 Views

MySQL VersionAs we know that MySQL 5 introduced views, hence, first of all, we need to check for the version of MySQL before starting writing and using stored procedures. It can be done with the following query −mysql> Select VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.20    | +-----------+ ... Read More

What is the C# equivalent of C++ friend keyword?

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 12:53:12

3K+ Views

friend in C#A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.A friend can be a ... Read More

How to open a plain text file in C#?

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 12:44:26

305 Views

To open a plain text file, use the StreamReader class. The following opens a file for reading −StreamReader sr = new StreamReader("d:/new.txt")Now, display the content of the file −while ((line = sr.ReadLine()) != null) {    Console.WriteLine(line); }Here is the code −Example Live Demousing System; using System.IO; namespace FileApplication { ... Read More

Class and Static Variables in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 12:38:08

8K+ Views

Static variables are used for defining constants because their values can be retrieved by invoking the class without creating an instance of it. Static variables can be initialized outside the member function or class definition. You can also initialize static variables inside the class definition.Example Live Demousing System; namespace StaticVarApplication ... Read More

What is the use of ON COMPLETION PRESERVE clause while creating the event?

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 12:37:00

3K+ Views

As we know that an event is automatically dropped when it is expired and we would not be able to see it from SHOW EVENTS statement. To change such kind of behavior we can use ON COMPLETION PRESERVE while creating the event. It can be understood from the following example ... Read More

Advertisements