Server Side Programming Articles

Page 788 of 2109

How to generate the first 100 Odd Numbers using C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 948 Views

To generate the first 100 odd numbers in C#, you can use different approaches. The most straightforward method is to iterate through numbers and check if they are odd using the modulus operator. Syntax Following is the syntax for checking if a number is odd − if (number % 2 != 0) { // number is odd } Following is the syntax for generating odd numbers in a loop − for (int i = 1; i

Read More

What is the difference between Write() and WriteLine() methods in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 6K+ Views

The difference between Write() and WriteLine() methods in C# is based on the new line character. Both methods are used to display output to the console, but they handle line termination differently. Write() method displays the output but does not provide a new line character, so subsequent output appears on the same line. WriteLine() method displays the output and automatically adds a new line character at the end, moving the cursor to the next line for subsequent output. Syntax Following is the syntax for Write() method − Console.Write(value); Console.Write("text"); Following is the syntax ...

Read More

Random Numbers in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 22K+ Views

The Random class in C# is used to generate pseudo-random numbers. It provides various methods to generate random integers, doubles, and bytes within specified ranges. Syntax Following is the syntax for creating a Random object and generating random numbers − Random rd = new Random(); int randomNumber = rd.Next(minValue, maxValue); Following are the commonly used methods of the Random class − rd.Next() // Random int from 0 to int.MaxValue rd.Next(maxValue) ...

Read More

Remove Leading Zeros from a String in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 15K+ Views

Removing leading zeros from a string is a common requirement in C# when dealing with numeric data or formatted strings. There are several approaches to accomplish this task, with TrimStart() being the most straightforward method. Syntax Following is the syntax for using TrimStart() to remove leading zeros − string.TrimStart('0') string.TrimStart(new char[] { '0' }) Using TrimStart() Method The TrimStart() method removes specified characters from the beginning of a string. To remove leading zeros, we pass '0' as the character to trim − using System; class Program { ...

Read More

Typeof() vs GetType() in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 17K+ Views

In C#, both typeof() and GetType() are used to obtain type information, but they work differently. typeof() is a compile-time operator that returns the Type object for a specified type, while GetType() is a runtime method that returns the actual type of an object instance. Syntax Following is the syntax for using typeof() operator − Type type = typeof(TypeName); Following is the syntax for using GetType() method − Type type = objectInstance.GetType(); Using typeof() Operator The typeof() operator takes a type name as its argument and returns the Type ...

Read More

How to generate the first 100 even Numbers using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 3K+ Views

To generate the first 100 even numbers in C#, you can use a for loop and check if each number is divisible by 2. An even number has no remainder when divided by 2, which can be tested using the modulo operator (%). What are Even Numbers? Even numbers are integers that are divisible by 2 without a remainder. Examples include 2, 4, 6, 8, 10, and so on. The condition number % 2 == 0 identifies even numbers. Even Number Test Number 8 ...

Read More

Using the new keyword in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 8K+ Views

The new keyword in C# is used to create instances of objects, arrays, and collections. It allocates memory for the object and calls the appropriate constructor to initialize it. Syntax Following is the syntax for using the new keyword to create objects − ClassName objectName = new ClassName(); Following is the syntax for creating arrays using new − dataType[] arrayName = new dataType[size]; Following is the syntax for creating collections using new − CollectionType collectionName = new CollectionType(); Using 'new' to Create Objects The most ...

Read More

Different ways for Integer to String Conversions in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 16K+ Views

Converting integers to strings is a common operation in C# programming. There are several built-in methods available, each with different use cases and performance characteristics. Syntax Following are the main syntaxes for integer to string conversion − // Using ToString() method string str = number.ToString(); // Using Convert.ToString() method string str = Convert.ToString(number); // Using string interpolation string str = $"{number}"; // Using string.Format() method string str = string.Format("{0}", number); Using ToString() Method The ToString() method is the most commonly used approach for converting integers to strings. It's called directly ...

Read More

The Object Class in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

The Object class is the base class of all classes in C# and the .NET Framework. Every class in C# implicitly inherits from the Object class, which means all objects have access to the fundamental methods provided by this base class. When you create any class in C#, it automatically inherits from Object even if you don't explicitly specify it. This provides a common set of methods that every object can use. Syntax Every class implicitly inherits from Object − public class MyClass { // This class inherits from Object automatically } ...

Read More

What is the difference between declaration and definition in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 12K+ Views

In C#, declaration means specifying the type and name of a variable, method, or class without providing an initial value or implementation. Definition (or initialization) means providing an actual value or implementation to what was declared. This distinction applies to variables, arrays, methods, and classes. Understanding the difference helps write cleaner code and avoid compilation errors. Syntax Following is the syntax for declaration − datatype variableName; Following is the syntax for definition/initialization − variableName = value; // or combined declaration and initialization datatype variableName = value; Variable Declaration vs ...

Read More
Showing 7871–7880 of 21,090 articles
« Prev 1 786 787 788 789 790 2109 Next »
Advertisements