Found 34494 Articles for Programming

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

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

5K+ 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

535 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

589 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

435 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

4K+ 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

What is the difference between a mutable and immutable string in C#?

karthikeya Boyini
Updated on 22-Jun-2020 07:18:45

3K+ Views

Mutable stringStringBuilder is a mutable string in C#. With StringBuilder, you can expand the number of characters in the string. The string cannot be changed once it is created, but StringBuilder can be expanded. It does not create a new object in the memory.Set StringBuilder −StringBuilder str = new StringBuilder();Let us see an example to learn how to work with StringBuilder in C# −Example Live Demousing System; using System.Text; public class Program {    public static void Main() {       StringBuilder str = new StringBuilder("Web World!!", 30);       str.Replace("World", "Arena");       Console.WriteLine(str);   ... Read More

What is static binding in C#?

Samual Sam
Updated on 22-Jun-2020 07:21:02

732 Views

The linking of a function with an object during compile time is called static binding. C# provides two techniques to implement static polymorphism: Function overloading and Operator overloading.In Function Overloading, you can have multiple definitions for the same function name in the same scope.Examplevoid print(int i) {    Console.WriteLine("Printing int: {0}", i ); } void print(double f) {    Console.WriteLine("Printing float: {0}" , f); }Overloaded operators are functions with special names. The keyword operator IS followed by the symbol for the operator being defineD.Examplepublic static Box operator+ (Box b, Box c) {    Box box = new Box();   ... Read More

Write a C# program to check if the entered number is Armstrong number?

Chandu yadav
Updated on 22-Jun-2020 07:21:29

195 Views

A number is an Armstrong number if the sum of the cube of each digit of the number is equal to the number itself.Here, we will find out the remainder and will sum it to the cube of remainder.rem = i % 10; sum = sum + rem*rem*rem;Then if the above sum that comes out after loop iteration is equal to the sum, then it will be an Armstrong number.if (sum == num) {    Console.Write("Armstrong Number!"); }The following is an example −Exampleint num, rem, sum = 0; // checking for armstrong number num = 153; for (int i ... Read More

What is method hiding in C#?

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

1K+ Views

Method hiding is also known as shadowing. The method of the parent class is available to the child class without using the override keyword in shadowing. The child class has its own version of the same function.Use the new keyword to perform shadowing.Let us see an example.Example Live Demousing System; using System.Collections.Generic; class Demo {    public class Parent {       public string GetInfo () {          return "This is Parent Class!";       }    }    public class Child : Parent {       public new string GetInfo() {   ... Read More

Advertisements