Programming Articles

Page 818 of 2547

Convert string to bool in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

To convert a string to a bool in C#, you can use several methods. The most common approaches are bool.Parse(), bool.TryParse(), and Convert.ToBoolean(). Each method has different behaviors for handling invalid input. Syntax Following is the syntax for converting string to bool using different methods − bool result = bool.Parse(stringValue); bool result = Convert.ToBoolean(stringValue); bool.TryParse(stringValue, out bool result); Using bool.Parse() The bool.Parse() method converts a string representation of a boolean value to its boolean equivalent. It accepts "True" or "False" (case-insensitive) and throws an exception for invalid values − using System; ...

Read More

C# Linq FirstorDefault Method

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 20K+ Views

The FirstOrDefault() method in C# LINQ returns the first element of a sequence, or a default value if the sequence is empty or no element matches the specified condition. This method is useful when you need to safely retrieve the first element without throwing an exception. Syntax Following is the syntax for using FirstOrDefault() − // Without condition public static T FirstOrDefault(this IEnumerable source); // With condition public static T FirstOrDefault(this IEnumerable source, Func predicate); Parameters source − The sequence to return the first element from. predicate (optional) ...

Read More

Binary to decimal using C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 406 Views

Converting binary numbers to decimal is a fundamental operation in programming. In C#, you can convert binary to decimal using manual calculation methods or built-in functions. The binary number system uses base 2, where each digit position represents a power of 2. How Binary to Decimal Conversion Works Binary to decimal conversion follows a simple mathematical principle. Each binary digit (bit) is multiplied by the corresponding power of 2, starting from 2⁰ for the rightmost digit − Binary 1010 → Decimal 10 1 ...

Read More

What is the Count property of ArrayList class in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 349 Views

The Count property in the ArrayList class returns the number of elements currently stored in the ArrayList. This property is read-only and provides an efficient way to determine the size of the collection. Syntax Following is the syntax for accessing the Count property − int count = arrayListName.Count; Return Value The Count property returns an int value representing the total number of elements in the ArrayList. Using Count Property with ArrayList First, create an ArrayList and add elements to it − ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); ...

Read More

C# program to convert string to long

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 15K+ Views

Converting a string to a long data type in C# can be accomplished using several methods. The most common approaches are long.Parse(), Convert.ToInt64(), and long.TryParse() for safe conversion. Syntax Following are the different syntaxes for converting string to long − long result = long.Parse(stringValue); long result = Convert.ToInt64(stringValue); bool success = long.TryParse(stringValue, out long result); Using long.Parse() Method The long.Parse() method converts a string representation of a number to its 64-bit signed integer equivalent − using System; class Demo { static ...

Read More

Int16.Equals Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 209 Views

The Int16.Equals() method in C# is used to return a value indicating whether this instance is equal to a specified object or Int16. This method provides two overloads − one for comparing with another Int16 value and another for comparing with any object. Syntax Following is the syntax for both overloads − public bool Equals(short ob); public override bool Equals(object ob); Parameters For the first overload − ob − An Int16 value to compare to this instance. For the second overload − ob − The object to ...

Read More

Bitwise right shift operators in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 854 Views

The bitwise right shift operator (>>) in C# moves the bits of the left operand to the right by the number of positions specified by the right operand. This operation effectively divides the number by powers of 2. Syntax Following is the syntax for the bitwise right shift operator − result = operand >> numberOfPositions; How It Works When you right shift a binary number, each bit moves to the right by the specified number of positions. Vacant positions on the left are filled with zeros for positive numbers and ones for negative ...

Read More

Overriding Vs Shadowing in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

In C#, overriding and shadowing are two different mechanisms for changing method behavior in derived classes. Overriding provides true polymorphism using virtual methods, while shadowing (method hiding) creates a new method that hides the base class method without polymorphic behavior. Overriding Overriding allows a subclass to provide a specific implementation of a method that is already defined in its base class. It requires the base class method to be marked as virtual or abstract, and the derived class method to use the override keyword. Method Overriding Base Class ...

Read More

KeyValuePair in C#

George John
George John
Updated on 17-Mar-2026 12K+ Views

The KeyValuePair struct in C# stores a pair of values in a single object, where one value acts as the key and the other as the value. It is commonly used in collections like List and as the element type in dictionaries. KeyValuePair is particularly useful when you need to associate two related pieces of data together without creating a custom class or when working with dictionary enumerations. Syntax Following is the syntax for creating a KeyValuePair − KeyValuePair pair = new KeyValuePair(key, value); Following is the syntax for accessing key and value ...

Read More

How to use the GetLowerBound method of array class in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 542 Views

The GetLowerBound() method of the Array class in C# returns the lower bound of the specified dimension in an array. For most arrays in C#, the lower bound is typically 0, but this method becomes useful when working with arrays that have custom bounds or multi-dimensional arrays. Syntax Following is the syntax for the GetLowerBound() method − public int GetLowerBound(int dimension); Parameters dimension − A zero-based dimension of the array whose lower bound needs to be found. Return Value Returns an integer representing the lower bound of the specified ...

Read More
Showing 8171–8180 of 25,466 articles
« Prev 1 816 817 818 819 820 2547 Next »
Advertisements