Found 34494 Articles for Programming

Difference between Boxing and Unboxing in C#

Samual Sam
Updated on 30-Jul-2019 22:30:23

883 Views

Boxing convert value type to an object type whereas unboxing converts object type to the value type. Let us see the difference between Boxing and Unboxing in C#. Storage In boxing, the value stored on the stack is copied to the object stored on heap memory, whereas unboxing is the opposite. In Unboxing, the object's value stored on the heap memory is copied to the value type stored on stack. Conversion Unboxing has explicit conversion whereas boxing has implicit conversion. Example int a = 10; object obj = a; // boxing int b = (int) ob; // unboxing

Difference between Abstract Class and Interface in C#

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

480 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 few methods are to be declared by the base class and the deriving class implements the functionalities. Let us now see the difference between Abstract class and Interface in C#. Inherit A class may inherit more than one interface, whereas a class may inherit only one abstract class. Member Field You ... Read More

Difference between == and .Equals method in c#

karthikeya Boyini
Updated on 23-Jun-2020 09:23:20

6K+ Views

The Equality Operator ( ==) is the comparison operator and the Equals() method in C# is used to compare the content of a string.The Equals() method compares only content.Example Live Demousing System; namespace ComparisionExample {    class Program {       static void Main(string[] args) {          string str = "hello";          string str2 = str;          Console.WriteLine("Using Equality operator: {0}", str == str2);          Console.WriteLine("Using equals() method: {0}", str.Equals(str2));          Console.ReadKey();       }    } }OutputUsing Equality operator: True Using equals() method: ... Read More

Delegates in C#

Chandu yadav
Updated on 23-Jun-2020 09:24:41

194 Views

A delegate in C# is a reference to the method. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class.Let us see how to declare delegates in C#.delegate Let us see an example to learn how to work with Delegates in C#.Example Live Demousing System; using System.IO; namespace DelegateAppl {    class PrintString {       static FileStream fs;       static StreamWriter sw;       ... Read More

Default constructor in C#

Samual Sam
Updated on 23-Jun-2020 09:25:13

238 Views

A Constructor in C# is invoked automatically when an object gets created. The constructor has the same name as that of the class, for example −public class Department {    public Department () {       Console.WriteLine("Default Constructor! ");    } }The following is the code that shows the usage of default constructor in C#. The constructor invokes immediately when the object gets created.Department dept1 = new Department ();A default constructor is a constructor that has no argument, for example −Department () { }Let us see the complete example to learn how to work with default contructors.Example Live Demousing System; ... Read More

Constructors in C#

karthikeya Boyini
Updated on 23-Jun-2020 09:27:50

369 Views

A Constructor in C# gets invoked automatically when a object gets created. The constructor has the same name as that of the class, for example −public class Department {    public Department () {       Console.WriteLine("Default Constructor! ");    } }The following is the code that shows the usage of constructor in C#.Example Live Demousing System; public class Department {    public Department () {       Console.WriteLine("Constructor Invoked");    }    public static void Main(string[] args) {       Department dept1 = new Department ();    } }OutputConstructor Invoked

Constructor Overloading in C#

Ankith Reddy
Updated on 23-Jun-2020 09:14:03

2K+ Views

When more than one constructor with the same name is defined in the same class, they are called overloaded, if the parameters are different for each constructor.Let us see an example to learn how to work with Constructor Overloading in C#.In the example, we have two subjects and a string declaration for Student Name.private double SubjectOne; private double SubjectTwo; string StudentName;We are showing result of three students in different subjects. For our example, to show constructor overloading, the name is only displayed for student 3rd.Student s1 = new Student(); Student s2 = new Student(90); Student s3 = new Student("Amit", 88, ... Read More

Compound assignment operators in C#

Samual Sam
Updated on 23-Jun-2020 09:14:59

3K+ Views

A compound assignment operator has a shorter syntax to assign the result. The operation is performed on the two operands before the result is assigned to the first operand.The following are the compound assignment operators in C#.Sr.NoOperator & Operator Name1+=Addition Assignment2-=Subtraction Assignment3*=Multiplication Assignment4/=Division Assignment5%=Modulo Assignment6&=Bitwise AND Assignment7|=Bitwise OR Assignment8^=Bitwise XOR Assignment9=Right Shift Assignment11=>Lambda OperatorLet us see an example to learn how to work with compound assignment operators in C#.Example Live Demousing System; namespace Program {    class MyClass {       public static void Main(string[] args) {          int val = 7;          val ... Read More

Composition vs Aggregation in C#

Arjun Thakur
Updated on 23-Jun-2020 09:16:12

3K+ Views

CompositionUnder Composition, if the parent object is deleted, then the child object also loses its status. Composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.public class Engine {    . . . } public class Car {    Engine eng = new Engine();    ....... }AggregationAggregation is a directional relation between objects in C#. It is the relationship between objects.For example, Employee and AddressAn Employee is associated with a single Department, whereas a Department can have more than one employee. Let us see ... Read More

Compilation and Execution of a C# Program

Chandu yadav
Updated on 30-Jul-2019 22:30:23

19K+ Views

To compile and execute a program in C#, you just need to click the Run button or press F5 key to execute the project in Microsoft Visual Studio IDE. Compile a C# program by using the command-line instead of the Microsoft Visual Studio IDE − Open a text editor and add the above-mentioned code. Save the file as helloworld.cs Open the command prompt tool and go to the directory where you saved the file. Type csc helloworld.cs and press enter to compile your code. If there are no errors in your code, the command prompt takes you to the next line and ... Read More

Advertisements