Found 33676 Articles for Programming

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

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

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

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

395 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

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

What is the difference between String.Copy() and String.CopyTo() methods in C#?

Arjun Thakur
Updated on 22-Jun-2020 07:22:38

335 Views

String.CopyTo() method gets the string characters and places them into an array. A group of characters are copied from source string into a character array.The following is the Copy() method −Example Live Demousing System; class Demo {    static void Main(String[] args) {       string str = "This is it!";       char[] ch = new char[5];       str.CopyTo(2, ch, 0, 2);       Console.WriteLine("Output...");       Console.WriteLine(ch);    } }OutputOutput... isString.Copy() creates a new string object with similar content.Example Live Demousing System; class Demo {    static void Main(String[] args) { ... Read More

Write a C# program to do basic arithmetic calculations

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

621 Views

Let us do the following arithmetic calculations −Sr.NoOperator & Description1+Adds two operands2-Subtracts second operand from the first3*Multiplies both operands4/Divides numerator by de-numeratorThe following is an example to perform arithmetic calculations using the above-given operators −Example Live Demousing System; namespace OperatorsApplication {    class Program {       static void Main(string[] args) {          int a = 40;          int b = 20;          int c;          c = a + b;          Console.WriteLine("Addition: {0}", c);          c = a - b;          Console.WriteLine("Subtraction: {0}", c);                c = a * b;          Console.WriteLine("Multiplication: {0}", c);          c = a / b;          Console.WriteLine("Division: {0}", c);          Console.ReadLine();       }    } }OutputAddition: 60 Subtraction: 20 Multiplication: 800 Division: 2

Write a C# program to find GCD and LCM?

Ankith Reddy
Updated on 22-Jun-2020 07:24:03

1K+ Views

GCD (Greatest Common Divisor)GCD is the largest positive integer that divides each of the integers.LCM (Least Common Multiple)LCM of two numbers is the smallest integer divisible by both the numbers.The following is an example to calculate the GCD and LCM. Here, we are calculating the LCM and GCD of 10 and 16 −Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class Program {       static void Main(string[] args) {          int val1, val2, n1, n2, x;          int resLCM, resGCD;          val1 ... Read More

What is the difference between String.Copy() and String.Clone() methods in C#?

George John
Updated on 21-Jun-2020 16:55:18

534 Views

The String.Copy() method creates a new instance of String. This is same as the specified String.The following is an example of Copy() method −Example Live Demousing System; class Demo {    static void Main(String[] args) {       string str1 = "mark";       string str2 = "marcus";       Console.WriteLine("str1 = '{0}'", str1);       Console.WriteLine("str2 = '{0}'", str2);       Console.WriteLine("After using String.Copy...");       str2 = String.Copy(str1);       Console.WriteLine("str1 = '{0}'", str1);       Console.WriteLine("str2 = '{0}'", str2);    } }Outputstr1 = 'mark' str2 = ... Read More

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

karthikeya Boyini
Updated on 21-Jun-2020 16:54:30

1K+ Views

An interface is a class without fields or method implementation. It cannot implement the methods it defines.A class generally implements the methods defined in an interface.InterfaceInterfaces 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.public interface interface_name {    // interface_members }ClassClass is a blueprint for a data type. This does not actually define any data, but it does define what the class name means. That is, what an object of the class consists of and what ... Read More

What is the difference between literal and constant in C#?

Chandu yadav
Updated on 21-Jun-2020 16:55:46

585 Views

The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.An integer literal can be a decimal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, and there is no prefix id for decimal.150 300uA floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part.3.14159 235468E-7FString ... Read More

Advertisements