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
Set 6-item tuple in C#'
A 6-item tuple in C# is a data structure that can hold six values of different or same data types. Tuples are useful when you need to return multiple values from a method or group related data together without creating a separate class. Syntax Following is the syntax for creating a 6-item tuple using the Tuple class − var tuple = new Tuple(item1, item2, item3, item4, item5, item6); Alternatively, you can use the modern tuple syntax with parentheses − var tuple = (item1, item2, item3, item4, item5, item6); Using Traditional ...
Read MoreC# Program to convert a Double to an Integer Value
To convert a double value to an integer value in C#, you can use several methods. The most common approach is using the Convert.ToInt32() method, which performs rounded conversion, or explicit casting for truncation. The Int32 data type represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647. Syntax Following are the different syntaxes for converting double to integer − // Using Convert.ToInt32() - rounds to nearest integer int result = Convert.ToInt32(doubleValue); // Using explicit casting - truncates decimal part int result = (int)doubleValue; ...
Read MoreDateTimeOffset.AddMinutes() Method in C#
The DateTimeOffset.AddMinutes() method in C# adds a specified number of whole and fractional minutes to a DateTimeOffset instance. This method returns a new DateTimeOffset object with the updated time while preserving the original offset from UTC. The method is particularly useful when working with time-zone aware calculations, as it maintains the timezone offset information throughout the operation. Syntax Following is the syntax − public DateTimeOffset AddMinutes(double minutes); Parameters minutes − A double value representing the number of minutes to add. Can be positive (to add) or negative (to subtract). Fractional values ...
Read MoreC# Program to Count the Number of 1's in the Entered Numbers
This C# program demonstrates how to count the occurrences of a specific number (1) in an array of integers. We'll use an array to store the numbers and iterate through it to count how many times the value 1 appears. Syntax Following is the syntax for declaring an array and using a foreach loop to iterate through it − int[] arrayName = new int[] {value1, value2, value3}; foreach(int variable in arrayName) { // process each element } Using Array and foreach Loop The most straightforward approach is to use ...
Read MoreWhat are dynamic arrays in C#?
Dynamic arrays are growable arrays that can resize themselves during runtime, providing a significant advantage over static arrays which have a fixed size. In C#, you can create dynamic arrays using collections like ArrayList and the more modern List. These dynamic collections allow automatic memory allocation, resizing, adding, searching, and sorting items efficiently. The ArrayList stores objects of any type, while List is type-safe and performs better. Syntax Following is the syntax for creating an ArrayList − ArrayList arrayList = new ArrayList(); arrayList.Add(item); Following is the syntax for creating a generic List − ...
Read MoreWhat are the interfaces implemented by Array class in C#?
The System.Array class in C# implements several important interfaces that provide essential functionality for array operations. These interfaces include ICloneable, IList, ICollection, and IEnumerable, each serving specific purposes in array manipulation and iteration. Understanding these interfaces helps you leverage the full capabilities of arrays in C# and work with them more effectively in different scenarios. Interfaces Implemented by Array Class Interface Purpose Key Methods/Properties ICloneable Creates a shallow copy of the array Clone() IList Provides indexed access and modification this[index], Add(), Remove() ICollection Provides count and ...
Read MoreImportant Keywords in C#
C# provides several important keywords that control class behavior, method accessibility, and parameter handling. These keywords include sealed, params, internal, this, and abstract, each serving specific purposes in object-oriented programming. Sealed Keyword The sealed keyword prevents a class from being inherited or a method from being overridden. When applied to a method, it must be an overridden method in a derived class. Syntax public sealed class ClassName { } public sealed override void MethodName() { } Example using System; class Animal { public virtual void ...
Read MoreC# Program to check if a character is a whitespace character
In C#, a whitespace character includes spaces, tabs, newlines, and other invisible characters used for formatting text. The char.IsWhiteSpace() method provides an easy way to identify these characters programmatically. Syntax Following is the syntax for using char.IsWhiteSpace() method − bool result = char.IsWhiteSpace(character); Parameters The method takes a single parameter − character − The character to be tested for whitespace. Return Value Returns true if the character is a whitespace character; otherwise, returns false. Using char.IsWhiteSpace() with Different Whitespace Characters The method recognizes various types of ...
Read MoreImplicit conversion from Byte to Decimal in C#
Byte represents an 8-bit unsigned integer that can store values from 0 to 255. Implicit conversion from byte to decimal is possible in C# because there is no loss of data − all byte values can be exactly represented as decimal values. Implicit conversion happens automatically without requiring any casting operator or explicit conversion method. Syntax The syntax for implicit conversion from byte to decimal is − byte byteValue = value; decimal decimalValue = byteValue; // Implicit conversion How Implicit Conversion Works When you assign a byte value to a decimal variable, ...
Read MoreUInt16.GetTypeCode() Method in C# with Examples
The UInt16.GetTypeCode() method in C# is used to return the TypeCode for value type UInt16. This method is part of the IConvertible interface and provides a way to identify the underlying data type at runtime. The TypeCode enumeration represents different data types in .NET, and for all UInt16 values, this method always returns TypeCode.UInt16. Syntax Following is the syntax for the UInt16.GetTypeCode() method − public TypeCode GetTypeCode(); Return Value This method returns TypeCode.UInt16, which is the enumerated constant for the UInt16 data type. Using GetTypeCode() with Different UInt16 Values Example ...
Read More