Found 2628 Articles for Csharp

What does the interface IStructuralEquatable do in C#?

Samual Sam
Updated on 20-Jun-2020 16:03:02

250 Views

The IStructuralEquatable interface defines methods to support the comparison of objects for structural equality, which means that two objects are equal because they have equal values.It includes the following two methods −Sr.NoMethod & Description1Equals(Object,  IEqualityComparer)The method determined whether an object is structurally equal to the current instance.2GetHashCode(IEqualityComparer)The methods a hash code for the current instance.Let us see an example in which I have created Tuple objects and worked with IstructuralEquatable interface:Create Tuples −var tupleOne = Tuple.Create(26.3, Double.NaN, 35.6); var tupleOne = Tuple.Create(26.3, Double.NaN, 35.6);Now check the equality by calling IStructuralEquatable.Equals using default comparer.IStructuralEquatable chk = tupleOne; Console.WriteLine(chk.Equals(tupleTwo, EqualityComparer.Default));Read More

What are Tuples in C#4.0?

karthikeya Boyini
Updated on 20-Jun-2020 16:04:01

703 Views

Tuples has a sequence of elements of different data types. It was introduced to return an instance of the Tuple with no need to specify the type of each element separately.Let us create a tuple with two elements. The following is how you declare a tuple. −Tupleperson = new Tuple (32, "Steve");Now, for the example check for the first item in the tuple, which is an integer −if (tuple.Item1 == 99) {    Console.WriteLine(tuple.Item1); }Now check for second item in the tuple, which is a string −if (tuple.Item2 == "Steve") {    Console.WriteLine(tuple.Item2); }The following is an example to create ... Read More

What is late binding in C#?

Samual Sam
Updated on 20-Jun-2020 15:48:03

918 Views

In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time. Dynamic polymorphism is what we call late binding.Dynamic polymorphism is implemented by abstract classes and virtual functions. The following is an example showing an example of dynamic polymorphism −Example Live Demousing System; namespace PolymorphismApplication {    class Shape {       protected int width, height;       public Shape( int a = 0, int b = 0) {          width = a;          height = b;       ... Read More

What is a parameterized constructor in C# programs?

Chandu yadav
Updated on 20-Jun-2020 15:52:22

3K+ Views

In a constructor you can also add parameters. Such constructors are called parameterized constructors. This technique helps you to assign initial value to an object at the time of its creation.The following is an example −// class class DemoParameterized constructor with a prarameter rank −public Demo(int rank) { Console.WriteLine("RANK = {0}", rank); }Here is the complete example displaying how to work with parameterized constructor in C# −Example Live Demousing System; namespace Demo {    class Line {       private double length; // Length of a line             public Line(double len) { //Parameterized constructor ... Read More

What is default constructor in C# programs?

karthikeya Boyini
Updated on 20-Jun-2020 15:52:54

605 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 constructors −Example Live ... Read More

What is composition in C#?

Arjun Thakur
Updated on 20-Jun-2020 15:54:17

412 Views

If the parent object is deleted under Composition, then the child object also loses its status. The 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();       ....... }

What is a Ternary operator/conditional operator in C#?

Ankith Reddy
Updated on 20-Jun-2020 15:55:02

256 Views

Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.For example −y = (x == 1) ? 70 : 100;Above, if the first operand evaluates to true (1), the second operand is evaluated. If the first operand evaluates to false (0), the third operand is evaluated.The following is an example −Example Live Demousing System; namespace DEMO {    class Program {       static void Main(string[] args) {          int a, b;          a = 10;          b = (a == 1) ? 20 : 30;          Console.WriteLine("Value of b is {0}", b);          b = (a == 10) ? 20 : 30;          Console.WriteLine("Value of b is {0}", b);          Console.ReadLine();       }    } }OutputValue of b is 30 Value of b is 20

What is compile time polymorphism in C#?

Samual Sam
Updated on 20-Jun-2020 15:55:55

1K+ Views

Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.The linking of a function with an object during compile time is called early binding. It is also called static binding. C# provides two techniques to implement static polymorphism. They are Function overloading and Operator overloading.In function overloading you can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument ... Read More

What are the methods and properties of the Thread class in C#?

George John
Updated on 20-Jun-2020 15:31:04

294 Views

Threads are lightweight processes. One common example of use of thread is implementation of concurrent programming by modern operating systems.The following are some of 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 ... Read More

What are the main parts of a C# program?

Samual Sam
Updated on 20-Jun-2020 15:32:32

2K+ Views

The main parts of a C# program includes −Namespace declarationA classClass methodsClass attributesA Main methodStatements and ExpressionsCommentsThe following is an example showing how to create a C# program −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          Console.WriteLine("Our first program in C#!");          Console.ReadKey();       }    } }OutputOur first program in C#!Here are the parts of the C# program we saw above −using System; - the using keyword is used to include the System namespace in the program. A program ... Read More

Advertisements