Samual Sam has Published 2310 Articles

How to use Null Coalescing Operator (??) in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:48:30

2K+ Views

The null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the type of another nullable (or not) value type operand, where an implicit conversion is possible.If the value of the first operand is null, then the operator returns ... Read More

How to capture divide by zero exception in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:40:58

4K+ Views

System.DivideByZeroException is a class that handles errors generated from dividing a dividend with zero.ExampleLet us see an example −using System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;       } ... Read More

How can I use SUBSTRING_INDEX() function to get the substring as output which is between two same delimiters in a string?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:40:33

307 Views

We need to use nested SUBSTRING_INDEX() function for getting the substring as output which is between two same delimiters in a string. For example, from the string ‘www.tutorialspoint.com’, we want the substring ‘tutorialspoint’, which is in between two same delimiters ‘.’ as output then SUBSTRING_INDEX() function can be used in ... Read More

How to define custom methods in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:38:03

1K+ Views

To define a custom method in C#, use the following syntax − (Parameter List) { Method Body }The following are the various elements of a method −Access Specifier − This determines the visibility of a variable or a method from another class.Return type − A method may return a ... Read More

Why we do not have global variables in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:35:21

244 Views

C# does not have global variables and the scope resolution operator used in C++ for global variables is related to namespaces. It is called global namespace alias.If you have a type that shares an identifier in a different namespace, then to identify them using the scope resolution operator.For example, to ... Read More

Why do we use comma operator in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:19:46

879 Views

Comma operator in C# can be used as a separator in method argument list. You can also use it is an operator in a for statement.The following is an example showing using a comma operator in a for statement for initialization −for (int i = begin, j = 1; i

Working with DateTime in C#

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:16:17

792 Views

The DateTime class in C# is used to represent date and time in C#.The following are some of the properties of DateTime in C# −Sr.NoProperty & Description1DateGets the Date component2DayGets the day of the month3HourGets the hour of the month4MinuteGets the minute of the date5MonthGets the month of the dateLet ... Read More

What is the method for sorting a list in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:07:16

142 Views

The sort a list in C#, use the Sort() method.Let us first create a list −List myList = new List();Now add elements −myList.Add("Audi"); myList.Add("BMW"); myList.Add("Chevrolet"); myList.Add("Hyundai");Use the Sort() method to sort the list −myList.Sort();The following is an example showing how to sort a list in C# −Example Live Demousing System; using ... Read More

What is the Count property of Queue class in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:04:13

156 Views

Use the Count property to find the count of elements of the Queue class. Set elements like the following declaration −Queue q = new Queue(); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); q.Enqueue(4);Then use the Count property to count the elements −q.CountThe following is an example showing how to work with Count property ... Read More

How is a new object created in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 11:01:50

138 Views

Like any other object-oriented language, C# also has object and classes. Objects are real-world entities and instance of a class. Access the members of the class using an object.To access the class members, you need to use the dot (.) operator after the object name. The dot operator links the ... Read More

Advertisements