To get the index of a specified key in a SortedList object, use the IndexOfKey() method. This method returns the zero-based index of the key within the sorted collection, or -1 if the key is not found. Syntax Following is the syntax for the IndexOfKey() method − public virtual int IndexOfKey(object key) Parameters key − The key to locate in the SortedList object. Return Value Returns the zero-based index of the key parameter if found; otherwise, returns -1. Example The following example demonstrates how to find the ... Read More
The Console class in C# provides properties to determine the maximum possible window dimensions for a console application. The LargestWindowHeight and LargestWindowWidth properties return the largest height and width that the console window can have on the current system. These properties are useful when you need to maximize the console window or ensure your application's display fits within the system's constraints. Syntax Following is the syntax for getting the largest window height − int maxHeight = Console.LargestWindowHeight; Following is the syntax for getting the largest window width − int maxWidth = ... Read More
Finding the missing number and the repeated number in a sorted array is a common programming problem. This article demonstrates how to solve this problem without using any built-in functions in C#. The approach uses a boolean array to track which numbers are present and an integer array to count occurrences. By traversing the original array and marking elements in auxiliary arrays, we can identify both the missing and repeated elements efficiently. Algorithm Overview The solution works in two main steps − Finding the missing number: Create a boolean array and mark elements as ... Read More
The SortedList class in C# maintains its elements in sorted order by key. To get the key at a specified index, use the GetKey() method. Since SortedList automatically sorts elements alphabetically by key, the index positions correspond to the sorted order, not the insertion order. Syntax Following is the syntax for getting a key at the specified index − public virtual object GetKey(int index) Parameters index − The zero-based index of the key to get. Return Value Returns the key at the specified index of the SortedList ... Read More
To get the specified members of the current Type in C#, we use the GetMember() method from the System.Reflection namespace. This method allows us to retrieve information about specific members of a type, such as fields, properties, methods, and events. Syntax Following is the syntax for getting specified members of a Type − Type.GetMember(string name) Type.GetMember(string name, BindingFlags bindingAttr) Type.GetMember(string name, MemberTypes type, BindingFlags bindingAttr) Parameters name − The string containing the name of the member to get. bindingAttr − A bitmask comprised of one or more BindingFlags that ... Read More
The minimum number of jumps problem involves finding the least number of jumps required to reach the end of an array, where each element represents the maximum number of positions you can jump forward from that index. Given an array where each element represents the maximum jump length from that position, we need to find the minimum jumps to reach the last index. For example, in array {1, 3, 6, 3, 2, 3, 6, 8, 9, 5}, we can reach the end in 4 jumps. Jump Path Visualization 1 ... Read More
In this article, we are going to discuss how we can find prime numbers present within a given range using C#. What are Prime Numbers? Prime numbers are natural numbers greater than 1 that have exactly two factors − 1 and the number itself. They have no other positive divisors. Examples of prime numbers are 2, 3, 5, 7, 11, 13, 17, etc. Key Facts: The smallest prime number is 2, which is also the only even prime number. The number 1 is not a prime number because it has only one factor (itself). All ... Read More
The MathF.Asinh() method in C# returns the inverse hyperbolic sine (arc hyperbolic sine) of a specified single-precision floating-point number. This method is part of the System namespace and is commonly used in mathematical calculations involving hyperbolic functions. The inverse hyperbolic sine function is the inverse of the hyperbolic sine function. For any real number x, Asinh(x) returns the value y such that sinh(y) = x. Syntax Following is the syntax for the MathF.Asinh() method − public static float Asinh(float val); Parameters val − A single-precision floating-point number representing the hyperbolic sine ... Read More
The SortedSet class in C# provides a way to store unique elements in sorted order. To add elements to a SortedSet, you use the Add() method, which automatically maintains the sorted order and prevents duplicate entries. Syntax Following is the syntax for adding elements to a SortedSet − SortedSet sortedSet = new SortedSet(); bool added = sortedSet.Add(element); Parameters element − The element to add to the SortedSet. Return Value The Add() method returns a bool value: true − If the element was successfully added (not a duplicate). false ... Read More
The MathF.Atan() method in C# is used to return the angle whose tangent is given as a float value argument. This method returns the arctangent (inverse tangent) of the specified number, with the result expressed in radians between -π/2 and π/2. Syntax Following is the syntax for the MathF.Atan() method − public static float Atan (float val); Parameters val − A float representing a tangent value. This parameter can be any real number including positive infinity, negative infinity, or NaN (Not a Number). Return Value The method ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance