Karthikeya Boyini has Published 2383 Articles

How to convert a number from Decimal to Binary using recursion in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 12:54:49

364 Views

To get the binary of Decimal, using recursion, firstly set the decimal number −int dec = 30;Now pass the value to a function −public int displayBinary(int dec) { }Now, check the condition until the decimal value is 0 and using recursion get the mod 2 of the decimal num as ... Read More

How to use string.Empty or String.Empty to initialize a string in C#?

karthikeya Boyini

karthikeya Boyini

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

556 Views

Set the string as empty using the string.Empty in C# −string myStr = string.Empty;To check whether it is a string or not, use the IsNullOrEmpty() method −if (string.IsNullOrEmpty(myStr)) {    Console.WriteLine("String is empty or null!"); }The following is an example −Example Live Demousing System; namespace Demo {    public class ... Read More

Local Inner Class in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 12:46:41

954 Views

A nested class is a class declared in another enclosing class and it has inner as well as outer class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested classLet us see an example code snippet ... Read More

Does declaring an array create an array in C#?

karthikeya Boyini

karthikeya Boyini

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

58 Views

Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.The following is a declaration and it will not create an array −int[] id;The following create an array of integers. The array is a reference type, so ... Read More

How to obtain Status of the Current Thread in C#?

karthikeya Boyini

karthikeya Boyini

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

165 Views

To get the status of current thread, use the IsAlive() method −Firstly, create a new thread −Thread t = Thread.CurrentThread; t.Name = "Our Thread";Now, to get the status of the current thread −t.IsAliveThe following is the complete code −Example Live Demousing System; using System.Threading; namespace Demo {    class MyClass ... Read More

How to insert an item in ArrayList in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 12:14:40

402 Views

To insert an item in an already created ArrayList, use the Insert() method.Firstly, set elements −ArrayList arr = new ArrayList(); arr.Add(45); arr.Add(78); arr.Add(33);Now, let’s say you need to insert an item at 2nd position. For that, use the Insert() method −// inserting element at 2nd position arr.Insert(1, 90);Let us ... Read More

How to iterate any Map in C#

karthikeya Boyini

karthikeya Boyini

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

1K+ Views

C# has no built-in Math type. For the same, use a Dictionary.Firstly, create a Dictionary −Dictionary d = new Dictionary(); d.Add("keyboard", 1); d.Add("mouse", 2);Get the keys −var val = d.Keys.ToList();Now, use the foreach loop to iterate over the Map −foreach (var key in val) {    Console.WriteLine(key); }To iterate ... Read More

How can we see the information on triggers order in case of multiple triggersfor same event and action time?

karthikeya Boyini

karthikeya Boyini

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

63 Views

It can be done with the help of the following query −mysql> SELECT trigger_name, action_order FROM INFORMATION_SCHEMA.triggers WHERE TRIGGER_SCHEMA = 'query' ORDER BY event_object_table, action_timing, event_manipulation; +------------------------------+--------------+ | trigger_name                 | action_order | +------------------------------+--------------+ | studentdetail_before_update  |            1 ... Read More

How to iterate over a C# dictionary?

karthikeya Boyini

karthikeya Boyini

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

352 Views

Firstly, add elements −IDictionary d = new Dictionary(); d.Add(1, 97); d.Add(2, 89); d.Add(3, 77); d.Add(4, 88);Now, get the keys −List myList = new List(d.Keys);To iterate −foreach (int k in myList) {    Console.WriteLine("{0}, {1}", k, d[k]); }The following is an example −Example Live Demousing System; using System.Collections.Generic; public class Demo ... Read More

How to list down all the files available in a directory using C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 12:09:50

310 Views

Firstly, use the DirectoryInfo object −//creating a DirectoryInfo object DirectoryInfo mydir = new DirectoryInfo(@"d:\amit");Now, use the GetFiles() method to get all the files −FileInfo [] f = mydir.GetFiles();To get the list of files in a directory, try to run the following code −Exampleusing System; using System.IO; namespace Demo { ... Read More

Advertisements