Tag: C#
How to Create an Interface in C# ?
You might need to few functionalities without defining any implementation of the abstract methods. This should later be applied to various types within your project. In this case , one can create an interface which specifies some behavior rather than what the type or member is all about. How to Create an Interface in C# ? Below is a sample interface called IMusic The interface…
How to Read from a Text File in C# ?
Below is a sample code snippet that demonstrates how to read from a text file in C# . How to Read from a Text File in C# ?
How to Throw an Exception in C# ?
To indicate and error which can be handled by the caller function , you can use the throw keyword to throw an exception . For example , below is a sample code snippet demonstrating how to throw an exception in C#. How to Throw an Exception in C# ?
How to use SQL like Operator in LINQ and C#?
In a SQL Query, one might use the Like Query which can be used along with the % operator to search of contains within the data. How to use SQL like Operator in LINQ and C#? This article will show it with a sample code snippet. How to use SQL like Operator in LINQ and C#? Below is a sample source code demonstrating the usage…
How to check if the number is positive or negative in C# ?
You can use the > and < operator to check if the number is a positive or negative number in C#. How to check if the number is positive or negative in C# ? If the number is less than zero , it can be considered as negative number. If the number is greater than zero , it is a positive number. Below is a…
Example of Lambda Expression with Action method with String as Parameter in C#
Below is a sample code snippet that demonstrates the lambda expression with action method with string as parameter in C#. Example of Lambda Expression with Action method with String as Parameter
How to detect if a key exists in a Dictionary in C# ?
If you want to detect if a key exists in a dictionary in C# , you can use the contains method of the dictionary which return true if the key is found. How to detect if a key exists in a Dictionary in C# ? Below is a sample source code that illustrates how to find out if the exists in a dictionary using the…
How to Create a Guid Value in C# ?
If you want to create a new Guid value in C# which is random , you can use the Guid class to achieve it. Below is a sample code snippet demonstrating how to do it. How to Create a Guid Value in C# ?
How to find the absolute value of a number in C# ?
Below is a sample code snippet that demonstrates how to find the absolute value of a number in C# . How to find the absolute value of a number in C# ?
How to get last four characters from a string in C#?
This post will provide a simple tip showing how you can get the last 4 characters from a string in C#. How to get last four characters from a string in C#? Assume that you have a string that contains the value “CodersEditor.com” and you wish to get .com from the string and display it. Below is a sample code snippet demonstrating how you can…
Returning Dictionary from LINQ Query in C#
Below is a sample source code demonstrating how to return Dictionary of<int, string> from the LINQ Query result. Returning Dictionary from LINQ Query in C#
How to Convert a Stream to Byte Array in C# 4.0 ?
One of the simplest way to convert a stream to byte array in C# 4.0 is to use the MemoryStream and perform the CopyTo operation on the source stream to the Memory Stream. How to Convert a Stream to Byte Array in C# 4.0 ? Below is a sample code snippet on how to convert a stream to byte array in C# 4.0.