Articles on Trending Technologies

Technical articles with clear explanations and examples

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

How to use #error and #warning directives in C#?

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

The #error and #warning directives in C# are preprocessor directives that allow developers to generate custom compiler errors and warnings during the compilation process. These directives are useful for conditional compilation scenarios and providing feedback about missing configurations or deprecated code paths. Syntax Following is the syntax for the #error directive − #error error-message Following is the syntax for the #warning directive − #warning warning-message Using #error Directive The #error directive generates a compile-time error with a custom message. This prevents the code from compiling and forces the developer ...

Read More

Understanding Logistic Regression in C#

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

Logistic regression is a statistical method used for binary classification problems. Unlike linear regression which predicts continuous values, logistic regression predicts the probability that an instance belongs to a particular category. It is widely used in medical science to predict disease outcomes and in business to forecast customer behavior. The key advantage of logistic regression is that it produces probabilities between 0 and 1, making it ideal for classification tasks. It also provides interpretable results through odds ratios and supports statistical hypothesis testing. Mathematical Foundation Logistic regression uses a linear model combined with the logistic function (sigmoid ...

Read More

Convert.ToDecimal Method in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 4K+ 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

Events vs Delegates in C#

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

In C#, both delegates and events provide mechanisms for method invocation, but they serve different purposes and have distinct characteristics. Events are built on top of delegates but provide additional safety and encapsulation features that make them more suitable for notification scenarios. Syntax Following is the syntax for declaring a delegate − public delegate void DelegateName(parameters); Following is the syntax for declaring an event − public delegate void DelegateName(parameters); public event DelegateName EventName; Delegates in C# A delegate is a reference type that holds references to methods with the ...

Read More

Type.GetElementType() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 273 Views

The Type.GetElementType() method in C# is used to return the Type of the object encompassed or referred to by the current array, pointer, or reference type. This method is particularly useful when working with collection types to discover what type of elements they contain. Syntax Following is the syntax − public abstract Type GetElementType(); Return Value Returns a Type object representing the element type of the current array, pointer, or reference type. If the current Type is not an array, pointer, or reference type, the method returns null. Using GetElementType() with Arrays ...

Read More

How to check if an item exists in a C# list collection?

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

In C#, you can check if an item exists in a List collection using several methods. The most common approach is the Contains() method, which returns true if the item is found and false otherwise. Syntax Following is the syntax for the Contains() method − bool Contains(T item) Parameters item − The object to locate in the list. The value can be null for reference types. Return Value Returns true if the item is found in the list; otherwise, false. Using Contains() Method Example using ...

Read More

String Formatting in C# to add padding on the right

vanithasree
vanithasree
Updated on 17-Mar-2026 328 Views

String formatting in C# provides several ways to add padding to strings. Right padding aligns text to the left by adding spaces to the right side of the string until it reaches the specified width. Syntax Following is the syntax for right padding using composite formatting − string.Format("{0, -width}", value) Following is the syntax for right padding using string interpolation − $"{value, -width}" Following is the syntax for right padding using the PadRight() method − string.PadRight(totalWidth) string.PadRight(totalWidth, paddingChar) Right Padding Visualization ...

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

Date Class in C#

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

The DateTime class in C# is used to work with dates and times. It represents an instant in time, ranging from 12:00:00 midnight, January 1, 0001 to 11:59:59 P.M., December 31, 9999 A.D. The DateTime class provides various methods and properties to create, manipulate, and format date and time values. Syntax Following is the syntax for creating a DateTime object − DateTime variableName = new DateTime(year, month, day); DateTime variableName = new DateTime(year, month, day, hour, minute, second); To get the current date and time − DateTime current = DateTime.Now; ...

Read More
Showing 11391–11400 of 61,303 articles
Advertisements