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 96 of 2547
How to find the product of 2 numbers using recursion in C#?
Finding the product of two numbers using recursion in C# is an interesting approach that demonstrates how multiplication can be implemented using only addition and recursive function calls. Instead of using the standard multiplication operator, we build the product by repeatedly adding one number to itself. How Recursive Multiplication Works The concept is based on the mathematical principle that multiplication is repeated addition. For example, 5 × 3 = 5 + 5 + 5. In recursion, we add the first number to itself and reduce the second number by 1 until it reaches zero. ...
Read MoreStreamWriter in C#
The StreamWriter class in C# is used to write characters to a stream in a particular encoding. It provides an easy way to create and write text to files, making it essential for file I/O operations. StreamWriter automatically handles file creation and provides various methods to write text data efficiently. Syntax Following is the syntax for creating a StreamWriter object − StreamWriter writer = new StreamWriter("filename.txt"); Using the using statement ensures automatic disposal − using (StreamWriter writer = new StreamWriter("filename.txt")) { writer.WriteLine("text"); } Basic File Writing ...
Read MoreC# Console BufferHeight Property
The Console.BufferHeight property in C# gets or sets the height of the buffer area in rows. The buffer height represents the maximum number of text rows that can be stored in the console's internal buffer before older lines are discarded. This property is particularly useful when you need to control how much output history the console retains or when working with console applications that produce large amounts of output. Syntax Following is the syntax for using the BufferHeight property − // Get buffer height int height = Console.BufferHeight; // Set buffer height Console.BufferHeight = ...
Read MoreDateTime.FromBinary() Method in C#
The DateTime.FromBinary() method in C# is used to deserialize a 64-bit binary value and recreate an original serialized DateTime object. This method is particularly useful when you need to restore a DateTime object that was previously converted to its binary representation using ToBinary(). Syntax Following is the syntax − public static DateTime FromBinary(long dateData); Parameters dateData: A 64-bit signed integer that encodes the Kind property in a 2-bit field and the Ticks property in a 62-bit field. Return Value This method returns a DateTime object that is equivalent to the DateTime ...
Read MoreDecimal.ToInt64() Method in C#
The Decimal.ToInt64() method in C# is used to convert the value of the specified Decimal to the equivalent 64-bit signed integer (long). This method truncates the decimal portion, returning only the whole number part. Syntax Following is the syntax − public static long ToInt64(decimal val); Parameters val − The decimal number to convert to a 64-bit signed integer. Return Value This method returns a long value that represents the truncated decimal value. The fractional part is discarded, not rounded. How It Works The method performs ...
Read MoreGroupBy() Method in C#
The GroupBy() method in C# is a LINQ extension method that groups elements from a collection based on a specified key selector function. It returns an IGrouping where elements sharing the same key are grouped together. Syntax Following is the syntax for the GroupBy() method − public static IEnumerable GroupBy( this IEnumerable source, Func keySelector ) Parameters source − The collection to group elements from. keySelector − A function that extracts the key for each element. Return Value Returns an ...
Read MoreWhat is the scope of a private member variable of a class in C#?
The scope of a private member variable in C# is limited to the class in which it is declared. Only methods and properties within the same class can directly access private members. This implements the principle of data encapsulation, which hides internal implementation details from external code. Syntax Following is the syntax for declaring private member variables − private dataType variableName; Private members can only be accessed by methods within the same class − class ClassName { private int value; public void ...
Read MoreDateTime.FromFileTime() Method in C#
The DateTime.FromFileTime() method in C# converts a Windows file time to an equivalent local time. Windows file time represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (UTC). Syntax Following is the syntax − public static DateTime FromFileTime(long fileTime); Parameters The method takes one parameter − fileTime − A Windows file time expressed in ticks (100-nanosecond intervals since January 1, 1601 UTC). Return Value Returns a DateTime object that represents the local time equivalent of the Windows file time ...
Read MoreComments in C#
Comments in C# are used to document and explain code, making it more readable and maintainable. The C# compiler ignores all comments during compilation, so they don't affect the program's performance. C# supports three types of comments: single-line, multi-line, and XML documentation comments. Syntax Following is the syntax for single-line comments − // This is a single-line comment Following is the syntax for multi-line comments − /* This is a multi-line comment that spans multiple lines */ Following is the syntax for XML documentation comments − ...
Read MoreHow to compare two tuples in C#?
Tuple comparison was introduced in C# 7.3, allowing you to easily compare two tuples using equality operators. Tuples are compared element-wise, meaning each corresponding element in both tuples must be equal for the tuples to be considered equal. Syntax Following is the syntax for comparing tuples using the equality operator − bool result = tuple1 == tuple2; You can also use the inequality operator − bool result = tuple1 != tuple2; How Tuple Comparison Works Tuple comparison in C# follows these rules: Tuples must have the same ...
Read More