Ankith Reddy has Published 996 Articles

C# Program to get the name of the drive

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 14:33:38

187 Views

Set the drive for which you want to display the name −DriveInfo info = new DriveInfo("C");Now, to get the drive name, use the Name property −info.NameHere is the complete code with output −Exampleusing System; using System.Linq; using System.IO; public class Demo {    public static void Main() {     ... Read More

TakeWhile method in C# ()

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 14:31:14

466 Views

With the TakeWhile() method, you can get methods by setting a condition base on Predicate.Firstly, declare and initialize an array −int[] arr = { 25, 40, 65, 70};Now, use the TakeWhile() method and predicate to get all the elements that are less than 30.var val = arr.TakeWhile(ele => ele < ... Read More

C# Program to set the timer to zero

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 14:18:51

455 Views

To set the timer information to zero, use the Stopwatch Restart method.Firstly, begin the Stopwatch −Stopwatch s = Stopwatch.StartNew();Then, use Restart() to set the timer to zero −s.Restart();Let us see the complete code −ExampleLive Demousing System; using System.Threading; using System.Diagnostics; public class Demo {    public static void Main() { ... Read More

ContainsKey in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 14:17:07

2K+ Views

ContainsKey is a Dictionary method in C# and check whether a key exists in the Dictionary or not.Declare a Dictionary and add elements −var dict = new Dictionary() {    {"TV", 1},    {"Home Theatre", 2},    {"Amazon Alexa", 3},    {"Google Home", 5},    {"Laptop", 5},    {"Bluetooth Speaker", ... Read More

C# Program to find the smallest element from an array

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 14:14:43

2K+ Views

Declare an array −int[] arr = { 5, 9, 2, 7 };Now to get the smallest element from an array, use the Min() method −arr.Min());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 5, 9, 2, 7 };       Console.WriteLine(arr.Min());    } }Output2

C# program to display the next day

Ankith Reddy

Ankith Reddy

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

3K+ Views

To display the next day, use the AddDays() method and a value +1 to get the next day.Firstly, use the following to get the current day −DateTime.TodayNow, add 1 to the AddDays() method to get the next day −DateTime.Today.AddDays(1)The following is the code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; ... Read More

C# TicksPer constants

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 14:11:18

239 Views

TicksPer constants in C# have TicksPerDay, TicksPerHour, TicksPerMinute, TicksPerSecond, and TicksPerMillisecond constants. A millisecond consists of 10, 000 ticks.Here are the TicksPer constants −TimeSpan.TicksPerDay TimeSpan.TicksPerHour TimeSpan.TicksPerMinuteExample Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       // TicksPer constant       Console.WriteLine(TimeSpan.TicksPerDay); ... Read More

Enum.GetName in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 13:57:32

629 Views

Gets the string representation of an Enum value using the Enum.GetName.It has two parameters −Type − Enumeration typeObject − Value of an enumerationThe following is an example −Example Live Demousing System; class Demo {    enum Vehicle {       Car,       Motorbike,       Truck, ... Read More

C# program to count number of bytes in an array

Ankith Reddy

Ankith Reddy

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

1K+ Views

Set a byte array −byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 };To count number of bytes −Buffer.ByteLength(b)The following is the code −Example Live Demousing System; class Program {    static void Main() {       byte[] b = { 5, 9, 19, 23, 29, 35, ... Read More

C# program to find the index of a word in a string

Ankith Reddy

Ankith Reddy

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

588 Views

Declare and initialize an array −string[] str = new string[] {    "Cat",    "Mat",    "Rat" };Now, ue IndexOf() method to find the index of the word “Mat” −Array.IndexOf(str, "Mat");The following is the code −Example Live Demousing System; public class Demo {    public static void Main() {   ... Read More

Advertisements