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 867 of 2547
Print first m multiples of n in C#
To print the first m multiples of a given number n in C#, we use a loop to iterate and calculate each multiple. This is useful for displaying multiplication tables or generating sequences. Syntax Following is the basic syntax for printing multiples using a loop − for (int i = 1; i
Read MoreDifferences between C++ and C#
C++ is a statically typed, compiled, general-purpose, case-sensitive programming language that supports procedural, object-oriented, and generic programming paradigms. It is regarded as a middle-level language because it combines both high-level and low-level language features. C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative, led by Anders Hejlsberg. Both languages share some similarities but differ significantly in design philosophy and implementation. Key Differences Between C++ and C# Memory Management C++ uses manual memory management where developers must explicitly allocate and deallocate memory using new and delete operators. C# features automatic ...
Read MoreConvert.ToDouble(String, IFormatProvider) Method in C#
The Convert.ToDouble(String, IFormatProvider) method in C# converts a string representation of a number to an equivalent double-precision floating-point number using specified culture-specific formatting information. This method is particularly useful when working with numeric strings that follow different regional formatting conventions. Syntax Following is the syntax − public static double ToDouble(string value, IFormatProvider provider); Parameters value − A string that contains the number to convert. provider − An object that supplies culture-specific formatting information. If null, the current culture is used. Return Value Returns a double-precision floating-point number equivalent to ...
Read Morestatic keyword in C#
The static keyword in C# is used to declare class members that belong to the class itself rather than to any specific instance. When a member is declared as static, it means there is only one copy of that member shared across all instances of the class. Static members can be accessed directly using the class name without creating an object instance. They are commonly used for utility methods, constants, and shared data that should be consistent across all instances of a class. Syntax Following is the syntax for declaring static members − public static ...
Read MoreHow to compare two Dates in C#?
To compare dates in C#, you need to first set two dates to be compared using the DateTime object. The DateTime class in C# provides several methods and operators for date comparison including direct comparison operators, the CompareTo() method, and specialized methods like Equals(). Syntax Following are the different syntaxes for comparing dates − // Using comparison operators if (date1 < date2) { } if (date1 > date2) { } if (date1 == date2) { } // Using CompareTo method int result = date1.CompareTo(date2); // Using Equals method bool isEqual = date1.Equals(date2); ...
Read MoreHow to print duplicate characters in a String using C#?
Finding duplicate characters in a string is a common programming task in C#. A duplicate character is one that appears more than once in the string. We can solve this by counting the frequency of each character and then displaying those with a count greater than 1. Using Character Frequency Array The most efficient approach uses an integer array to store the frequency of each character. Since there are 256 possible ASCII characters, we create an array of size 256 − using System; class Demo { static int maxCHARS = 256; ...
Read MoreHow to generate a string randomly using C#?
Generating random strings in C# is useful for creating passwords, test data, or unique identifiers. There are several approaches to generate random strings, from simple character-based methods to more advanced techniques using predefined character sets. Syntax Following is the basic syntax for generating random strings using Random class − Random random = new Random(); char randomChar = (char)random.Next(startValue, endValue); Following is the syntax using a character array − char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); char randomChar = chars[random.Next(chars.Length)]; Using ASCII Values for Random String Generation This method generates random characters by ...
Read MoreDifferent Methods to find Prime Numbers in C#
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In C#, there are several methods to check if a number is prime, each with different approaches and efficiency levels. What is a Prime Number? A prime number is divisible only by 1 and itself. For example, 2, 3, 5, 7, 11 are prime numbers. The number 1 is not considered prime, and 2 is the only even prime number. Prime vs Composite Numbers Prime Numbers ...
Read MoreConvert.ToSByte(String, IFormatProvider) Method in C#
The Convert.ToSByte(String, IFormatProvider) method in C# converts the specified string representation of a number to an equivalent 8-bit signed integer, using the specified culture-specific formatting information. This method is particularly useful when working with numeric strings that may have different formatting conventions based on locale. Syntax Following is the syntax − public static sbyte ToSByte(string value, IFormatProvider provider); Parameters value − A string that contains the number to convert. The value must be between -128 and 127. provider − An object that supplies culture-specific formatting information. This can be ...
Read MoreTernary Operator in C#
The ternary operator in C# is a conditional operator that provides a concise way to evaluate expressions based on a Boolean condition. It takes three operands and returns one of two values depending on whether the condition is true or false. The ternary operator is also known as the conditional operator and uses the syntax condition ? value_if_true : value_if_false. It's particularly useful for simple conditional assignments and can make code more readable when used appropriately. Syntax Following is the syntax for the ternary operator − result = condition ? value_if_true : value_if_false; ...
Read More