Arjun Thakur has Published 1025 Articles

C# Enum GetValues Method

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:18:16

2K+ Views

Get the array of the values of the constants in a specified enumeration.Here is our enum.enum Rank { Jack = 10, Tom = 19, Tim = 26 };Now, get all the values of the enum as an array and display using GetValues() method.foreach(int res in Enum.GetValues(typeof(Rank))) {    Console.WriteLine(res); }Let ... Read More

Composition vs Aggregation in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:16:12

3K+ Views

CompositionUnder Composition, if the parent object is deleted, then the child object also loses its status. Composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.public class Engine {    . . ... Read More

C# Program to return specified number of elements from the beginning of a sequence

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:10:41

166 Views

Set an array and arrange it in descending order using OrderByDescending.int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345};Now, use the Take() method to return specified number of elements from the beginning.Enumerable units = prod.AsQueryable().OrderByDescending(s => s).Take(2);Let us see the complete code.Example Live Demousing System; using System.Linq; ... Read More

Convert.ToByte Method in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:04:35

1K+ Views

The Convert.ToByte method is used to convert a specified value to an 8-bit unsigned integer.Let’s say we have a char variable.Char charVal = ‘a’;Now, convert it to an 8-bit unsigned integer.byte byteVal = Convert.ToByte(charVal);Let us see another example now.Example Live Demousing System; public class Demo {    public static void Main() ... Read More

Sortable ("s") Format Specifier in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 08:58:29

509 Views

The Sortable standard format specifier represents a custom date and time format string.The format string is defined by the DateTimeFormatInfo.SortableDateTimePattern property.The custom format string.yyyy'-'MM'-'dd'T'HH':'mm':'ssExample Live Demousing System; class Demo {    static void Main() {       DateTime date = new DateTime(2018, 9, 5, 2, 12, 40);       ... Read More

C# Linq Count method

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 08:57:19

669 Views

The Count method returns the count of elements in a sequence.Let us first set an array.string[] arr = { "Java", "C++", "Python"};Now, use the Count() method to count the array elements.arr.AsQueryable().Count();The following is the complete example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() { ... Read More

The "#" custom specifier in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 08:50:10

220 Views

The "#" custom format specifier works as a digit-placeholder symbol.If the value to be formatted has a digit in the position where the "#" symbol appears in the format string, then that digit is copied to the resultant string.We have set a double type here.double d; d = 4.2;Now, let ... Read More

C# Any Method

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 08:46:29

9K+ Views

The Any method checks whether any of the element in a sequence satisfy a specific condition or not.If any element satisfy the condition, true is returned.Let us see an example.int[] arr = {5, 7, 10, 12, 15, 18, 20};Now, using Any() method, we will check whether any of the element ... Read More

Represent Int64 as a Octal string in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 08:42:28

251 Views

To reprsent Int64 as a Octal string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 8 for Octal.Int64 represents a 64-bit signed integer.Firstly, set an Int64 variable.long val = 986766;Now, convert it to octal string by including 8 as the second ... Read More

Get rank of a three-dimensional array in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 08:39:23

166 Views

To get the rank of a three-dimensional array, use the Rank property.Set a three-dimensional array.int[,,] arr = new int[3,4,5]Now get the rank.arr.RankLet us see the complete code.Exampleusing System; class Program {    static void Main() {       int[,,] arr = new int[3,4,5]       Console.WriteLine("Dimensions of Array : " + arr.Rank);    } }

Advertisements