IComparable Interface in C#Use the IComparable Interface in C# to sort elements. It is also used to compare the current instance with another object of same type.It provides you with a method of comparing two objects of a particular type. Remember, while implementing the IComparable interface, CompareTo() method should also be implemented.Let us see an example −int IComparable.CompareTo(object ob) { Vehicle v=(Vehicle)ob; return String.Compare(this.make, v.make); }IComparer interface in C#The IComparer interface is used to sort elements that compare two objects and provides additional comparison method.Exampleprivate class sortYearAscendingHelper : IComparer { int IComparer.Compare(object ob1, object ob2) { ... Read More
Division operator is used in C# to divide numerator by denominator, for example 9/ 3The division operator comes under Arithmetic Operators in C#. Let us see a complete example to learn how to implement Arithmetic operators in C#, wherein we will see how to work with division operator.result = num1 / num2; Console.WriteLine("Division: Value is {0}", result);Above we have used division operator on num1 and num2.The following is the complete example.Example Live Demousing System; namespace Sample { class Demo { static void Main(string[] args) { int num1 = 50; ... Read More
Enum is Enumeration to store a set of named constants like year, product, month, season, etc.The default value of Enum constants starts from 0 and increments. It has fixed set of constants and can be traversed easily. However you can still change the start index and customize it with the value of your choice.In the following example, I have set the customized value to be 20 instead of the default 0.Example Live Demousing System; public class Demo { public enum Vehicle { Car =20, Motorcycle, Bus, Truck } public static void Main() { int a = ... Read More
To compare dates in C#, you need to first set two dates to be compared using the DateTime object. We will use the DateTime class in C#.Date 1DateTime date1 = new DateTime(2018, 07, 20); Console.WriteLine("Date 1 : {0}", date1);Date 2DateTime date2 = new DateTime(2018, 07, 25); Console.WriteLine("Date 2 : {0}", date2);Now let us compare both the dates in C#. The following is an example to compare dates in C#.Example Live Demousing System; namespace Program { class Demo { static int Main() { DateTime date1 = new DateTime(2018, 07, 20); ... Read More
Firstly, let us enter the number.Console.WriteLine("Enter a Number"); n = int.Parse(Console.ReadLine());Now loop through and find the mod of the entered number with i = 1 that increments after every iteration. If its 0, then print it, since it would be our factor.for (i= 1; i
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
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
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
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
To get the querystring of the href attribute of an area, use the search property. You can try to run the following code to search the querystring −Example var x = document.getElementById("myarea").search; document.write("Querystring: "+x);
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP