Samual Sam has Published 2492 Articles

C# program to convert an array to an ordinary list with the same items

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:24:36

74 Views

Set an array −int[] arr = { 23, 66, 96, 110 };Now, create a new list −var list = new List();Use the Add method and add the array elements to the list −for (int i = 0; i < arr.Length; i++) {    list.Add(arr[i]); }The following is the complete code ... Read More

File Searching using C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:14:39

492 Views

To search files from the list of files in a directory, try to run the following code −Exampleusing System; using System.IO; namespace Demo {    class Program {       static void Main(string[] args) {          //creating a DirectoryInfo object          DirectoryInfo ... Read More

What is the difference between VAR and DYNAMIC keywords in C#?

Samual Sam

Samual Sam

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

484 Views

DynamicStore any type of value in the dynamic data type variable created using dynamic keyword. Type checking for these types of variables takes place at run-time. Dynamic are dynamically typed variables.The following is the syntax for declaring a dynamic type −dynamic = value;The following is an example −dynamic val1 ... Read More

What is the difference between virtual and abstract functions in C#?

Samual Sam

Samual Sam

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

4K+ Views

Abstract methods do not provide an implementation and they force the derived classes to override the method. It is declared under abstract class. An abstract method only has the method definitionVirtual methods have an implementation, unlike the Abstract method and it can exist in the abstract and non-abstract class. It ... Read More

How can we create MySQL views without any column list?

Samual Sam

Samual Sam

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

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

How to check if two Strings are anagrams of each other using C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:02:55

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

C# program to multiply all numbers in the list

Samual Sam

Samual Sam

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

811 Views

Firstly, set the list −List myList = new List () {    5,    10,    7 };Now, set the value of a variable to 1 that would help us in multiplying −int prod = 1;Loop through and get the product −foreach(int i in myList) {    prod = prod*i; ... Read More

Merge two sorted arrays into a list using C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 12:55:32

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

How to convert a tuple into an array in C#?

Samual Sam

Samual Sam

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

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

Inheritance vs Composition in C#

Samual Sam

Samual Sam

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

549 Views

InheritanceWith Inheritance, you can designate that the new class should inherit the members of an existing class. This existing class is called the baseclass, and the new class is referred to as the derived class. Inheritance implements the IS-A relationship. For example, mammal IS A animal, dog IS-A mammal hence ... Read More

Advertisements