Ankith Reddy

Ankith Reddy

730 Articles Published

Articles by Ankith Reddy

Page 5 of 73

How to check if array contains a duplicate number using C#?

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

Checking if an array contains duplicate numbers is a common programming task in C#. There are multiple approaches to solve this problem, ranging from simple loops to LINQ methods and hash-based techniques. Using Dictionary to Count Occurrences The dictionary approach counts the frequency of each element in the array. Any element with a count greater than 1 is a duplicate − using System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { ...

Read More

What are circular references in C#?

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

A circular reference in C# occurs when two or more objects reference each other directly or indirectly, creating a dependency loop. This can cause memory leaks and prevent proper garbage collection if not handled correctly. The .NET garbage collector is designed to detect and handle circular references automatically. It uses a mark-and-sweep algorithm that starts from root objects (like static variables and local variables) and marks all reachable objects, then collects unmarked objects even if they have circular references. Understanding Circular References Circular references typically occur in parent-child relationships, linked lists, or complex object graphs where objects ...

Read More

C# program to count number of bytes in an array

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

In C#, you can count the number of bytes in an array using the Buffer.ByteLength() method. This method returns the total number of bytes occupied by all elements in the array, which is particularly useful when working with different data types that have varying byte sizes. Syntax Following is the syntax for using Buffer.ByteLength() − int byteCount = Buffer.ByteLength(array); Parameters array − The array whose byte length you want to determine. It must be an array of primitive types. Return Value The method returns an int representing ...

Read More

Initializing HashSet in C#

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

A HashSet in C# is a collection that stores unique elements and automatically eliminates duplicates. It provides fast lookups and is ideal when you need to ensure all elements are distinct. Syntax Following is the syntax for initializing a HashSet − var hashSet = new HashSet(); var hashSet = new HashSet(collection); var hashSet = new HashSet { element1, element2, element3 }; Using Array to Initialize HashSet You can initialize a HashSet with an existing array. The HashSet will automatically remove any duplicate values from the array − using System; using System.Collections.Generic; ...

Read More

Convert.ToInt64 Method in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 722 Views

The Convert.ToInt64 method in C# converts a specified value to a 64-bit signed integer (long). This method can convert various data types including strings, floating-point numbers, and other numeric types to a long value. Syntax Following are the common syntax overloads for Convert.ToInt64 − public static long ToInt64(object value); public static long ToInt64(string value); public static long ToInt64(double value); public static long ToInt64(float value); public static long ToInt64(decimal value); Parameters value − The value to convert to a 64-bit signed integer Return Value Returns a 64-bit signed integer (long) ...

Read More

What are floating point literals in C#?

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

A floating-point literal in C# represents a decimal number that can contain a fractional part. It consists of an integer part, a decimal point, a fractional part, and optionally an exponent part. You can represent floating point literals in either decimal form or exponential form. Syntax Following are the different forms of floating-point literal syntax − // Decimal form 123.45 0.5678 // Exponential form 1.23E+2 // 1.23 × 10² 4.56e-3 // 4.56 × 10⁻³ // With type suffixes 3.14f // float 2.718 ...

Read More

What are generic collections in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 826 Views

Generic collections in C# are type-safe collections that allow you to specify the type of elements at compile time. They provide better performance, type safety, and IntelliSense support compared to non-generic collections like ArrayList and Hashtable. The most commonly used generic collections include List, Dictionary, SortedList, Queue, and Stack. These are part of the System.Collections.Generic namespace. Syntax Following is the syntax for declaring generic collections − List listName = new List(); Dictionary dictName = new Dictionary(); SortedList sortedListName = new SortedList(); Where T, TKey, and TValue are type parameters that specify the actual ...

Read More

How to check if String is Palindrome using C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 587 Views

A palindrome is a string that reads the same forwards and backwards, such as "Level", "madam", or "racecar". In C#, there are several ways to check if a string is a palindrome. Using Array.Reverse() Method The simplest approach is to reverse the string and compare it with the original. First, convert the string to a character array − char[] ch = str.ToCharArray(); Then reverse the array using Array.Reverse() − Array.Reverse(ch); Finally, compare the reversed string with the original using case-insensitive comparison − bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase); ...

Read More

How to multiply a given number by 2 using Bitwise Operators in C#?

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

A number can be multiplied by 2 using bitwise operators. This is done by using the left shift operator (

Read More

C# Enum Parse Method

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

The Enum.Parse method in C# converts the string representation of an enum constant name or its numeric value into an equivalent enumerated object. This method is essential when you need to convert string data back into strongly-typed enum values. Syntax Following are the main syntax forms for Enum.Parse − // Basic syntax public static object Parse(Type enumType, string value) // With ignore case option public static object Parse(Type enumType, string value, bool ignoreCase) Parameters enumType − The type of the enumeration to parse to value − A string containing the name ...

Read More
Showing 41–50 of 730 articles
« Prev 1 3 4 5 6 7 73 Next »
Advertisements