Found 33676 Articles for Programming

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

karthikeya Boyini
Updated on 22-Jun-2020 07:24:40

3K+ Views

To generate first 100 even numbers, set a for loop from 1 to 100.for(val = 1; val

Typeof() vs GetType() in C#

Samual Sam
Updated on 22-Jun-2020 07:26:04

17K+ Views

Typeof()The type takes the Type and returns the Type of the argument.For example: System.Byte for the following −typeof(byte)The following is an example −Example Live Demousing System; class Program {    static void Main() {       Console.WriteLine(typeof(int));       Console.WriteLine(typeof(byte));    } }OutputSystem.Int32 System.ByteGetType()The GetType() method of array class in C# gets the Type of the current instance.To get the type.Type tp = value.GetType();In the below example, we are checking the int value using the type.if (tp.Equals(typeof(int))) Console.WriteLine("{0} is an integer data type.", value)The following is the usage of GetType() method in C#.Example Live Demousing System; class Program { ... Read More

Remove Leading Zeros from a String in C#

Ankith Reddy
Updated on 22-Jun-2020 07:26:30

14K+ Views

Let’s say the following is our string with leading zeros.String str ="000234";Use the TrimStart() method and set the 0 to remove it.TrimStart(new Char[] { '0' } )The following is the complete code to remove leading zeros.Example Live Demousing System; class Program {    static void Main() {       String str ="000234".TrimStart(new Char[] { '0' } );       Console.WriteLine(str);    } }Output234

Random Numbers in C#

karthikeya Boyini
Updated on 22-Jun-2020 07:27:06

22K+ Views

To generate random numbers in C#, use the Next(minValue, MaxValue) method. The parameters are used to set the minimum and maximum values.Next(100,200);We have set the above method under Random() object.Random rd = new Random(); int rand_num = rd.Next(100,200);The following is an example −Example Live Demousing System; class Program {    static void Main() {       Random rd = new Random();       int rand_num = rd.Next(100,200);       Console.WriteLine(rand_num);    } }Output182

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

Samual Sam
Updated on 22-Jun-2020 07:28:54

6K+ Views

The difference between Write() and WriteLine() method is based on new line character.Write() method displays the output but do not provide a new line character.WriteLine() method displays the output and also provides a new line character it the end of the string, This would set a new line for the next output.Let us see an example to learn about the difference between Write() and WriteLine() method −Example Live Demousing System; class Program {    static void Main() {       Console.Write("One");       Console.Write("Two");       // this will set a new line for the next output ... Read More

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

Chandu yadav
Updated on 22-Jun-2020 07:31:12

861 Views

To generate first 100 odd numbers, set a for loop from 1 to 100.for(val = 1; val

What is the System.Console class and its methods in C#?

karthikeya Boyini
Updated on 22-Jun-2020 07:29:16

879 Views

The System.Console class in C# represents the standard input, output, and error streams for console applications.The following are some of the methods of the System.Console class −Refer: MSDN System Class methodsSr.NoMethod & Description1Beep()Plays the sound of a beep through the console speaker.2Beep(Int32, Int32)Plays the sound of a beep of a specified frequency and duration through the console speaker.3Clear()Clears the console buffer and corresponding console window of display information.4MoveBufferArea(Int32, Int32, Int32, Int32, Int32, Int32)Copies a specified source area of the screen buffer to a specified destination area.5MoveBufferArea(Int32, Int32, Int32, Int32, Int32, Int32, Char, ConsoleColor, ConsoleColor)Copies a specified source area of the ... Read More

What is the difference between break and continue statements in C#?

George John
Updated on 22-Jun-2020 07:33:25

2K+ Views

The break statement terminates the loop and transfers execution to the statement immediately following the loop.The continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.The continue statement in C# works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.The following is the complete code to use continue statement in a ... Read More

What is the difference between an interface and an abstract class in C#?

Samual Sam
Updated on 22-Jun-2020 07:17:37

581 Views

Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members.Abstract classes to some extent serve the same purpose, however, they are mostly used when only a few methods are to be declared by the base class and the deriving class implements the functionalities.The following are the differences −A class may inherit more than one interface, whereas a class may inherit only one abstract class.Multiple Inheritance cannot be achieved using Abstract whereas with Interface we can achieve it.You ... Read More

Properties of the Thread Class

Ankith Reddy
Updated on 22-Jun-2020 07:17:04

6K+ Views

A thread is defined as the execution path of a program. Each thread defines a unique flow of control.The following are the properties of the Thread class −Sr.No.Property & Description1CurrentContextGets the current context in which the thread is executing.2CurrentCultureGets or sets the culture for the current thread.3CurrentPrincipleGets or sets the thread's current principal (for role-based security).4currentThreadGets the currently running thread.5CurrentUICultureGets or sets the current culture used by the Resource Manager to look up culture-specific resources at run-time.6ExecutionContextGets an ExecutionContext object that contains information about the various contexts of the current thread.7IsAliveGets a value indicating the execution status of the current ... Read More

Advertisements