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
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to calculate power of three using C#?
Calculating the power of a number in C# can be done using recursion, iteration, or built-in methods. This article demonstrates how to calculate powers with a focus on raising numbers to the power of 3, though the methods work for any exponent. Syntax Following is the syntax for a recursive power function − static long power(int baseNumber, int exponent) { if (exponent != 0) { return (baseNumber * power(baseNumber, exponent - 1)); } return 1; } ...
Read MoreHow to access elements from multi-dimensional array in C#?
To access elements from a multi-dimensional array in C#, you specify indices for each dimension using square brackets with comma-separated values. For example, a[2, 1] accesses the element at row 3, column 2 (using zero-based indexing). Syntax Following is the syntax for accessing elements from a multi-dimensional array − arrayName[index1, index2, ...indexN] For a 2D array, you use two indices − int element = array[rowIndex, columnIndex]; Understanding Array Indexing Multi-dimensional arrays use zero-based indexing, meaning the first element is at index [0, 0]. Consider this 4×2 array structure − ...
Read MoreC# ToEven property
The ToEven property is a value in the MidpointRounding enumeration that implements banker's rounding. When a number falls exactly between two integers, it rounds to the nearest even number. This method reduces bias in calculations compared to always rounding up or down. Syntax Following is the syntax for using MidpointRounding.ToEven − decimal.Round(value, digits, MidpointRounding.ToEven) Math.Round(value, digits, MidpointRounding.ToEven) Parameters value − The number to be rounded digits − Number of decimal places in the return value MidpointRounding.ToEven − Rounds to the nearest even number when the value is exactly halfway between two numbers ...
Read MoreHow to validate a URL using regular expression in C#?
To validate a URL using regular expressions in C#, you need to check for proper URL structure including protocols, domain names, and top-level domains. Regular expressions provide a powerful way to match URL patterns and ensure they conform to expected formats. URL Components to Validate A valid URL typically consists of the following components − Protocol: http or https Domain: The website name (e.g., example, google) Top-level domain: .com, .org, .net, .edu, etc. Optional path and query parameters: Additional URL components URL Structure Breakdown https:// ...
Read MoreWhat is garbage collection in C#?
The garbage collector (GC) in C# is an automatic memory management system that handles the allocation and release of memory for managed objects. It eliminates the need for manual memory management, preventing memory leaks and reducing programming errors. The garbage collector operates on the managed heap, where all reference type objects are stored. When objects are no longer referenced by the application, the GC automatically reclaims their memory space. How Garbage Collection Works Garbage Collection Process Object Created Memory Low ...
Read MoreWhat is the difference between list and dictionary in C#?
A List and Dictionary are both generic collections in C#, but they serve different purposes. A List stores elements in a sequential order with index-based access, while a Dictionary stores key-value pairs for fast lookups. Understanding when to use each collection type is crucial for writing efficient C# applications. Lists are ideal for ordered data where you need to access elements by position, while dictionaries are perfect for mapping relationships and quick key-based retrieval. Syntax Following is the syntax for creating a List − List listName = new List(); // or with initialization List listName ...
Read MoreHow to open a plain text file in C#?
In C#, you can open and read a plain text file using the StreamReader class from the System.IO namespace. The StreamReader provides methods to read character data from a stream in a particular encoding. Syntax Following is the basic syntax for opening a text file with StreamReader − StreamReader sr = new StreamReader("filepath"); For proper resource management, use the using statement − using (StreamReader sr = new StreamReader("filepath")) { // Read file content } Using StreamReader to Read Text Files The most common approach is ...
Read MoreHow to validate a string for a numeric representation using TryParse in C#
The TryParse method in C# is used to validate whether a string contains a valid numeric representation. It attempts to convert the string to a number and returns true if successful, or false if the conversion fails. This is safer than using Parse because it doesn't throw exceptions on invalid input. Syntax Following is the syntax for using TryParse − bool result = int.TryParse(stringValue, out int number); Parameters stringValue − The string to be parsed. out number − The output parameter that receives the parsed value if successful, or ...
Read MoreHow to get int value from enum in C#?
In C#, an enum (enumeration) is a value type that represents a group of named constants. By default, each enum value has an underlying integer value starting from 0. You can extract the integer value from an enum using type casting. Syntax Following is the syntax for casting an enum to int − int value = (int)EnumName.EnumValue; Following is the syntax for declaring an enum − public enum EnumName { Value1, Value2, Value3 } Using Default Integer Values By default, enum values are assigned integer values starting from 0 ...
Read MoreHow to convert Lower case to Upper Case using C#?
To convert lowercase to uppercase in C#, use the ToUpper() method. This method converts all lowercase characters in a string to their uppercase equivalents and returns a new string without modifying the original string. Syntax Following is the syntax for the ToUpper() method − string.ToUpper() string.ToUpper(CultureInfo) Parameters CultureInfo (optional) − Specifies the culture-specific formatting information. If not provided, the current culture is used. Return Value The ToUpper() method returns a new string with all lowercase characters converted to uppercase. The original string remains unchanged. Using ToUpper() Method ...
Read More