Programming Articles

Page 87 of 2547

C# program to check if two lists have at-least one element common

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

A common requirement in C# programming is to check if two lists share at least one common element. This can be achieved using various approaches, from simple nested loops to more efficient methods using HashSets and LINQ. The most efficient approach is to use HashSet operations or LINQ's Intersect() method, which provide optimal performance for finding common elements between collections. Using HashSet Intersection HashSet provides an Overlaps() method that efficiently checks if two sets have any common elements − using System; using System.Collections.Generic; public class Program { public static void ...

Read More

C# Percent ("P") Format Specifier

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 17K+ Views

The percent ("P") format specifier in C# is used to format numbers as percentages. It multiplies the number by 100 and appends a percentage sign (%) to create a string representation of the percentage value. Syntax Following is the syntax for using the percent format specifier − number.ToString("P") // Default precision (2 decimal places) number.ToString("Pn") // Specify n decimal places Where n represents the number of decimal places to display after the decimal point. How It Works The percent ...

Read More

Const vs Static vs Readonly in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

The const, static, and readonly keywords in C# serve different purposes for declaring fields and members. Understanding their differences is crucial for choosing the right approach based on your specific needs. Const Constant fields are compile-time constants that cannot be modified after declaration. They must be assigned a value at the time of declaration and are implicitly static. const int a = 5; Example using System; class Constants { public const int MaxValue = 100; public const string AppName = "MyApp"; public ...

Read More

Decimal.ToByte() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 302 Views

The Decimal.ToByte() method in C# converts a decimal value to its equivalent 8-bit unsigned integer (byte). This method truncates the decimal portion and returns only the integer part. The byte data type can store values from 0 to 255. Syntax Following is the syntax − public static byte ToByte(decimal val); Parameters val − The decimal number to convert to a byte value. Return Value Returns a byte value that represents the truncated integer portion of the specified decimal. If the decimal is negative, it rounds toward zero. How ...

Read More

What is the difference between implicit and explicit type conversion in C#?

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

Type conversion in C# refers to converting a value from one data type to another. There are two main types of conversions: implicit (automatic) and explicit (manual). Understanding when each occurs helps prevent data loss and compilation errors. Implicit Type Conversion Implicit conversions are performed automatically by the C# compiler when converting from a smaller data type to a larger one. This is safe because no data is lost in the process. Syntax smallerType variable = value; largerType newVariable = variable; // Automatic conversion Implicit Conversion Flow ...

Read More

C# Program to determine the difference in hours between two dates

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

In C#, you can calculate the difference in hours between two dates using the DateTime structure and the TimeSpan class. The TimeSpan represents a time interval and provides properties to get the difference in various units including hours. Syntax Following is the syntax for calculating the time difference − DateTime date1 = new DateTime(year, month, day, hour, minute, second); DateTime date2 = new DateTime(year, month, day, hour, minute, second); TimeSpan difference = date2 - date1; double hours = difference.TotalHours; Using DateTime Subtraction The most straightforward way to find the difference in hours is ...

Read More

BitConverter.DoubleToInt64Bits() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 129 Views

The BitConverter.DoubleToInt64Bits() method in C# converts a double-precision floating-point number to its 64-bit signed integer binary representation. This method is useful for examining the underlying binary structure of floating-point numbers or for low-level operations that require access to the raw bits. Syntax Following is the syntax for the DoubleToInt64Bits() method − public static long DoubleToInt64Bits(double value); Parameters value − The double-precision floating-point number to convert. Return Value Returns a 64-bit signed integer whose value is equivalent to the binary representation of the input double value. ...

Read More

Char.Equals() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 3K+ Views

The Char.Equals() method in C# is used to compare two character values for equality. It returns true if the character instance is equal to the specified character value, and false otherwise. This method is case-sensitive and performs an exact character comparison. Syntax Following is the syntax for the Char.Equals() method − public bool Equals(char value); public override bool Equals(object obj); Parameters value − A character to compare with the current character instance. obj − An object to compare with the current character instance. Return Value ...

Read More

C# program to check if all the values in a list that are greater than a given value

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

To check if all values in a list are greater than a given value, you need to iterate through each element and compare it against the threshold. If any element fails the condition, then not all values meet the criteria. There are multiple approaches to solve this problem in C# − using traditional loops, LINQ methods, or built-in array methods. Using Traditional For Loop The most straightforward approach uses a for loop to iterate through the array and check each element − using System; public class Program { public static ...

Read More

C# Program to add a node after the given node in a Linked List

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 377 Views

A LinkedList in C# is a doubly linked list that allows efficient insertion and removal of elements at any position. The AddAfter() method inserts a new node immediately after a specified existing node in the list. Syntax Following is the syntax for the AddAfter() method − public LinkedListNode AddAfter(LinkedListNode node, T value) Parameters node − The LinkedListNode after which to insert a new node containing value. value − The value to add to the LinkedList. Return Value The method returns the new LinkedListNode containing the ...

Read More
Showing 861–870 of 25,467 articles
« Prev 1 85 86 87 88 89 2547 Next »
Advertisements