File Searching Using C Hash

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

602 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 mydir = new DirectoryInfo(@"d:\amit");          // getting the files in the directory, their names and size          FileInfo [] f = mydir.GetFiles();          foreach (FileInfo file in f) {             Console.WriteLine("File Name: {0} Size: ... Read More

Compute Average for Set of Values Using Chash

karthikeya Boyini
Updated on 22-Jun-2020 13:13:36

315 Views

Firstly, set an array with values −int[] myArr = new int[] {    34,    23,    77,    67 };To get the average, firstly get the sum of array elements.Divide the sum with the length of the array and that will give you the average of the elements −int sum = 0; int average = 0; for (int i = 0; i < len; i++) {    sum += myArr[i]; } average = sum / len;The following is the complete code to get the array in C# −Example Live Demousing System; public class Program {    public static void Main() ... Read More

Difference Between var and dynamic Keywords in C#

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

664 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 = 100; dynamic val2 = 5; dynamic val3 = 20;The dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at runtime.VarThe "var" keyword initializes variables with var support. Just assign ... Read More

Difference Between Virtual and Abstract Functions in C#

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

5K+ 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 provides the derived classes with the option of overriding it.Virtual FunctionsThe virtual keyword is useful in modifying a method, property, indexer, or event. When you have a function defined in a class that you want to be implemented in an inherited class(es), you use virtual functions. The virtual functions could ... Read More

See MySQL Temporary Tables in the List of Tables

Priya Pallavi
Updated on 22-Jun-2020 13:10:17

331 Views

As we know that we can see the list of tables in a database with the help of SHOW TABLES statement. But MySQL temporary tables are not stored in this list or in other words we can say that we cannot see the temporary tables with the help of SHOW TABLES statement. To illustrate it we are using the following example −ExampleIn this example, we are trying to get the temporary table named ‘SalesSummary’ from SHOW TABLES statement as follows −mysql> SHOW TABLES LIKE '%Sales%'; Empty set (0.00 sec) mysql> SHOW TABLES LIKE '%SalesSummary%'; Empty set (0.00 sec)The above ... Read More

UnionWith Method in C#

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

747 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

199 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

885 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

514 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

Advertisements