Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 876 of 2547
Math.Sqrt() Method in C#
The Math.Sqrt() method in C# is used to compute the square root of a specified number. This static method is part of the System.Math class and returns a double value representing the positive square root of the input. Syntax Following is the syntax − public static double Sqrt(double val); Parameters val − A double-precision floating-point number for which to calculate the square root. Must be greater than or equal to zero for a valid numeric result. Return Value The method returns a double value with the following behavior − ...
Read MoreVariable Arguments (Varargs) in C#
The params keyword in C# allows a method to accept a variable number of arguments of the same type. This feature, known as variable arguments or varargs, enables you to call a method with any number of parameters without creating an array explicitly. Syntax Following is the syntax for declaring a method with variable arguments − public static returnType MethodName(params type[] parameterName) { // method body } The params keyword must be the last parameter in the method signature, and only one params parameter is allowed per method. Key Rules ...
Read MoreString slicing in C# to rotate a string
String slicing in C# allows you to rotate characters within a string by combining substrings. This technique uses the Substring() method to extract portions of a string and rearrange them to achieve the desired rotation effect. String rotation involves moving characters from one position to another within the string. For example, rotating the first two characters of "welcome" to the end results in "lcomewe". Syntax Following is the syntax for the Substring() method − string.Substring(startIndex, length) For string rotation, combine two substrings − string rotated = str.Substring(n) + str.Substring(0, n); ...
Read MoreString Formatting in C# to add padding
String formatting with padding in C# allows you to align text in columns by adding spaces to the left or right of strings. This is particularly useful for creating formatted tables, reports, or aligned output displays. Padding is controlled by format specifiers that define the width and alignment of each placeholder in the format string. Syntax The basic syntax for padding in format strings is − string.Format("{index, width}", value) Where − index − The parameter index (0, 1, 2, etc.) width − The total width of the field Positive width − ...
Read MoreC# Program to filter array elements based on a predicate
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 MoreHow to use #error and #warning directives in C#?
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 MoreUnderstanding Logistic Regression in C#
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 MoreConvert.ToDecimal Method in C#
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 MoreEvents vs Delegates in C#
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 MoreType.GetElementType() Method in C#
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