Server Side Programming Articles

Page 821 of 2109

Why is f required while declaring floats in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 890 Views

The f suffix is required when declaring float literals in C# because without it, the compiler treats decimal numbers as double by default. The f suffix explicitly tells the compiler that the literal should be treated as a float type. Why the 'f' Suffix is Needed In C#, numeric literals with decimal points are interpreted as double precision floating-point numbers by default. Since double has higher precision than float, implicit conversion from double to float is not allowed because it could result in data loss. Literal Type Assignment ...

Read More

Join, Sleep and Abort methods in C# Threading

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

The Thread class in C# provides several important methods to control thread execution: Join(), Sleep(), and Abort(). These methods allow you to synchronize threads, pause execution, and terminate threads when needed. Syntax Following is the syntax for the three main thread control methods − // Join method thread.Join(); thread.Join(timeout); // Sleep method Thread.Sleep(milliseconds); // Abort method (obsolete in .NET Core/.NET 5+) thread.Abort(); Join Method The Join() method blocks the calling thread until the target thread terminates. This ensures that the calling thread waits for another thread to complete before continuing execution. ...

Read More

C# Program to filter array elements based on a predicate

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

In C#, filtering array elements based on a predicate allows you to select elements that meet specific conditions. A predicate is a function that returns true or false for each element, determining whether it should be included in the result. The most common approach is using LINQ's Where method, which applies a predicate function to filter elements. You can also use traditional loops or the Array.FindAll method for filtering. Syntax Following is the syntax for filtering with LINQ's Where method − IEnumerable result = array.Where(element => condition); Following is the syntax for filtering ...

Read More

Convert.ToDecimal Method in C#

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

The Convert.ToDecimal() method in C# converts a specified value to a decimal number. This method can convert various data types including strings, integers, floating-point numbers, and other numeric types to the decimal type, which provides high precision for financial and monetary calculations. Syntax Following are the common syntax forms for Convert.ToDecimal() − decimal result = Convert.ToDecimal(value); decimal result = Convert.ToDecimal(stringValue, IFormatProvider); Parameters value − The value to convert to decimal. Can be string, int, double, float, bool, or other convertible types. IFormatProvider − Optional culture-specific formatting information for string ...

Read More

Set tuple as a method parameter in C#

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

In C#, you can pass tuples as method parameters to group related values together. This approach is useful when you need to pass multiple values to a method without creating a separate class or using multiple parameters. Syntax Following is the syntax for creating a tuple and passing it as a method parameter − // Creating a tuple var tuple = Tuple.Create(value1, value2, value3); // Method with tuple parameter static void MethodName(Tuple tuple) { // Access tuple items using Item1, Item2, Item3 } Using Classic Tuple as Method Parameter ...

Read More

Return a C# tuple from a method

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

A tuple in C# is a data structure that can hold multiple values of different types. You can return a tuple from a method, which is useful when you need to return multiple values from a single method call. There are two main ways to return tuples from methods in C# − using the Tuple class and using the newer value tuples with more concise syntax. Syntax Using the Tuple class − static Tuple MethodName() { return Tuple.Create(value1, value2, value3); } Using value tuples (C# 7.0 and later) − ...

Read More

Convert Decimal to Int64 (long) in C#

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

The Convert.ToInt64() method in C# converts a decimal value to a 64-bit signed integer (long). This conversion rounds the decimal to the nearest integer using banker's rounding (round to even) and truncates any fractional part. Syntax Following is the syntax for converting decimal to Int64 − long result = Convert.ToInt64(decimalValue); Parameters decimalValue − The decimal number to be converted to Int64. Return Value Returns a 64-bit signed integer equivalent of the specified decimal value, rounded to the nearest integer. Using Convert.ToInt64() for Basic Conversion The following example ...

Read More

C# Program to display the first element from an array

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

In C#, there are multiple ways to access the first element from an array. The most common approaches include using array indexing, the First() LINQ method, and the Take() method. Syntax Following is the syntax for accessing the first element using array indexing − dataType firstElement = arrayName[0]; Following is the syntax using the LINQ First() method − dataType firstElement = arrayName.First(); Using Array Indexing The simplest and most efficient way to get the first element is using zero-based indexing − using System; class Demo { ...

Read More

Return the total elements in a sequence as a 64-bit signed integer in C#

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

The LongCount() method in C# returns the total number of elements in a sequence as a 64-bit signed integer (long). This method is particularly useful when dealing with large datasets where the element count might exceed the range of a regular 32-bit integer. The LongCount() method is available in both LINQ to Objects and LINQ to Entities, and can be used with any IEnumerable or IQueryable collection. Syntax Following is the syntax for using LongCount() method − public static long LongCount(this IEnumerable source) public static long LongCount(this IEnumerable source, Func predicate) Parameters ...

Read More

Object Initializer in C#

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

An object initializer in C# allows you to initialize an object's properties or fields at the time of object creation without explicitly calling a constructor with parameters. This feature provides a more readable and concise way to create and initialize objects. Object initializers use curly braces {} to assign values to accessible properties or fields immediately after creating the object instance. Syntax Following is the basic syntax for object initializers − ClassName objectName = new ClassName() { PropertyName1 = value1, PropertyName2 = value2, ...

Read More
Showing 8201–8210 of 21,090 articles
« Prev 1 819 820 821 822 823 2109 Next »
Advertisements