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
Int32.CompareTo Method in C# with Examples
The Int32.CompareTo method in C# is used to compare the current integer instance with another integer or object and returns an indication of their relative values. This method is particularly useful for sorting operations and conditional comparisons. Syntax The Int32.CompareTo method has two overloads − public int CompareTo(int value); public int CompareTo(object value); Parameters value − An integer or object to compare with the current instance. Return Value Return Value Condition Meaning Less than zero (< 0) Current instance < ...
Read MoreC# Program to Check Whether the Entered Number is an Armstrong Number or Not
An Armstrong number (also called a narcissistic number) is a number that equals the sum of its digits raised to the power of the number of digits. For a 3-digit number, each digit is cubed and summed. For example, 153 is an Armstrong number because − 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 Armstrong Number Check Process 153 Original Number 1³ + 5³ + 3³ Sum of Cubes ...
Read MoreWhat is a dictionary in C#?
A Dictionary in C# is a generic collection that stores data in key-value pairs. It belongs to the System.Collections.Generic namespace and provides fast lookups based on unique keys. Each key in a Dictionary must be unique, while values can be duplicated. The Dictionary class implements the IDictionary interface and uses hash tables internally for efficient data retrieval. Syntax Following is the syntax for declaring a Dictionary − Dictionary dictionaryName = new Dictionary(); You can also use the interface type for declaration − IDictionary dictionaryName = new Dictionary(); Creating and ...
Read MoreWhat is the difference between String.Copy() and String.CopyTo() methods in C#?
The String.Copy() and String.CopyTo() methods in C# serve different purposes for copying string data. String.Copy() creates a new string object with the same content, while String.CopyTo() copies characters from a string into a character array. Syntax Following is the syntax for String.Copy() method − public static string Copy(string str) Following is the syntax for String.CopyTo() method − public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) Parameters String.Copy() Parameters: str − The string to copy. String.CopyTo() Parameters: sourceIndex − The index of ...
Read MoreC# Program to write an array to a file
Writing an array to a file in C# can be accomplished using the File.WriteAllLines method from the System.IO namespace. This method writes each array element as a separate line to the specified file. Syntax Following is the syntax for using File.WriteAllLines − File.WriteAllLines(string path, string[] contents); Parameters path − The file path where the array will be written contents − The string array to write to the file Using WriteAllLines Method The WriteAllLines method automatically creates the file if it doesn't exist and overwrites it ...
Read MoreHow do we access elements from the two-dimensional array in C#?
A two-dimensional array in C# can be thought of as a table structure with rows and columns. Elements are accessed using two indices: the row index and the column index, separated by a comma within square brackets. Syntax Following is the syntax for accessing elements from a two-dimensional array − dataType value = arrayName[rowIndex, columnIndex]; Following is the syntax for assigning values to elements − arrayName[rowIndex, columnIndex] = value; 2D Array Structure Columns [0] [1] [2] ...
Read MoreDecimal.FromOACurrency() Method in C#
The Decimal.FromOACurrency() method in C# converts a 64-bit signed integer containing an OLE Automation Currency value to its equivalent decimal representation. OLE Automation Currency stores currency values as scaled integers, where the value is multiplied by 10, 000 to preserve four decimal places of precision. Syntax Following is the syntax for the Decimal.FromOACurrency() method − public static decimal FromOACurrency(long val); Parameters val: A 64-bit signed integer that contains an OLE Automation Currency value to be converted. Return Value Returns a decimal value equivalent to the OLE Automation Currency value. The returned ...
Read MoreC# program to convert a list of characters into a string
Converting a list of characters into a string is a common operation in C#. There are several approaches to accomplish this task, each suitable for different scenarios and data structures. Syntax Following are the main syntax patterns for converting characters to strings − // Using string constructor with char array string result = new string(charArray); // Using string.Join() method string result = string.Join("", charList); // Using StringBuilder class StringBuilder sb = new StringBuilder(); sb.Append(charArray); string result = sb.ToString(); Using String Constructor with Character Array The most direct approach is using the ...
Read MoreWhy we do not have global variables in C#?
C# does not have global variables like those found in C or C++. Instead, C# follows an object-oriented paradigm where all data and methods must be contained within classes or structures. The global namespace alias (global::) is used to resolve naming conflicts between namespaces, not to access global variables. Why C# Doesn't Have Global Variables C# was designed with several principles that eliminate the need for global variables − Type Safety: Global variables can lead to unpredictable behavior and make debugging difficult. Object-Oriented Design: Everything must belong to a class or struct, promoting ...
Read MoreWhat is method hiding in C#?
Method hiding (also known as shadowing) in C# occurs when a derived class defines a method with the same name as a method in its base class, but without using the override keyword. The child class creates its own version of the method that hides the parent class method rather than overriding it. Method hiding uses the new keyword to explicitly indicate that the method is intended to hide the base class method. This is different from method overriding, which uses override and creates polymorphic behavior. Syntax Following is the syntax for method hiding using the new ...
Read More