Ankith Reddy has Published 1070 Articles

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

2K+ 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

177 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

533 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

Is it possible to resize an array in C#

Ankith Reddy

Ankith Reddy

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

4K+ Views

You cannot resize an array in C#, but using Array.Resize you can replace the array with a new array of different size.The following is our array −char[] ch = new char[10]; ch[0] = 'a'; ch[1] = 'b';Now, resize −Array.Resize(ref ch, 10);The following is the complete example −Example Live Demousing System; class ... 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

472 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

Default operator in C#

Ankith Reddy

Ankith Reddy

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

517 Views

Using the default, you can get the default value of every reference and value type. The expressions set as default are evaluated at compile-time.To get the default for int −default(int);To get the default for long −default(long)Let us see the code to display default values −Example Live Demousing System; public class ... Read More

Pair Class in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 13:20:45

4K+ Views

The Pair class is the KeyValuePair class that stores a pair of values in a single list with C#.Declare KeyValuePair −var myList = new Liststring, int>>(); Now, add some elements: myList.Add(new KeyValuePair("Laptop", 1)); myList.Add(new KeyValuePair("Desktop System", 2)); myList.Add(new KeyValuePair("Tablet", 3)); myList.Add(new KeyValuePair("Mobile", 4)); myList.Add(new KeyValuePair("E-Book Reader", 5)); myList.Add(new KeyValuePair("LED", 6));Display ... Read More

String Formatting in C# using %

Ankith Reddy

Ankith Reddy

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

244 Views

Use the String.Fornt to format a string using %.String.Format format controls in C# also includes percentage (%) This multiplies the value by 100 and appends a percentage sign.Let’s say our value is −double val = .322;Now, use String.Format and format −string.Format("string = {0:0.0%}", val);The following is an example −Example Live Demousing ... Read More

Advertisements