Arjun Thakur has Published 1109 Articles

What is the Keys property of SortedList class in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 10:49:39

72 Views

Get the keys in the SortedList using the keys property of SortedList class in C#. We have first set the SortedList property with elements.SortedList sl = new SortedList(); sl.Add("ST0", "One"); sl.Add("ST1", "Two"); sl.Add("ST2", "Three"); sl.Add("ST3", "Four"); sl.Add("ST4", "Five"); sl.Add("ST5", "Six"); sl.Add("ST6", "Seven");Now use the keys property to get the keys.ICollection ... Read More

What is the IsReadOnly property of SortedList class in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 10:03:48

71 Views

Use the IsReadOnly property to get a value indicating whether the SortedList is read-only or not.You can try to run the following code to implement IsReadOnly property in C#.Here, we have set the SortedList first.SortedList s = new SortedList();Added elements.s.Add("S001", "Jack"); s.Add("S002", "Henry");Now check for IsReadOnly.Console.WriteLine("IsReadOnly = " + s.IsReadOnly);The ... Read More

C# Nested Classes

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:54:58

2K+ Views

A nested class is a class declared in another enclosing class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested class.Let us see an example code snippet of nested classes in C#.Exampleclass One {    public ... Read More

C# program to replace n-th character from a given index in a string

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 09:43:40

1K+ Views

Firstly, set a string.string str1 = "Port"; Console.WriteLine("Original String: "+str1);Now convert the string into character array.char[] ch = str1.ToCharArray();Set the character you want to replace with the index of the location. To set a character at position 3rd.ch[2] = 'F';To remove nth character from a string, try the following C# ... Read More

C# Enum GetValues Method

Arjun Thakur

Arjun Thakur

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

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

110 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

851 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

362 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

451 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

Advertisements