Tag: csharp
How to find if the string is a number or not in C# ?
If you want to find out if the input string is a number in C# , you can use the try parse method. How to find if the string is a number or not in C# ? Below is a function in C# that demonstrates finding if the string is a number in C#.
How to Check if the ArrayList is read-only in C# ?
There are times when you would use the read-only wrapper in order to prevent modifying the ArrayList. We use the ArrayList.ReadOnly method to create such collection. When doing so , you might want to check if the ArrayList is Read-only or not. How to Check if the ArrayList is read-only in C# ? Use the IsReadOnly property defined in the ArrayList object to check this.
C#.NET Interview Questions and Answers – Part 2
C#.NET Interview Questions and Answers – Part 2 11. What are the different type of comments provided by C# for documentation ? C# supports three different types of comments– Single Line Comments Eg : //– Multi Line comments Eg : /* */– XML Documentation Comments Eg : /// 12. What are the predefined typed in C# ? The predefined types in C# includesValue types like…
Auto Property Initializers in C# 6.0
The .NET Framework 3.0 introduced the auto-implemented properties which was quite useful but it had one drawback . This did not have an option to specify the default value to the property . Here’s an example of the auto-implemented property in C#. If you had to specify the default value to property , you must either initialize the value in the constructor or by specifying…
Lambdas Expression for Getter-Only Auto-Properties in C# 6.0
C# 6.0 lets the developers use the lambda expression to implement the getter value of the read-only property . Whenever a lambda expression is found , the C# compiler identifies it as the property with only get method rather than a field. Lambdas Expression for Getter-Only Auto-Properties in C# 6.0 Below is a sample code snippet demonstrating the use of Lambdas Expression for Getter-Only Auto-Properties…
How to Populate XDocument from String in C# ?
To populate the XDocument from a string in C# , we can use the Parse method defined in the XDocument class. Below is a sample code snippet that demonstrates how to populate XDocument from string in C#. How to Populate XDocument from String in C# ?
Object Initializer in C#
Below is a sample sourecode demonstrating the Object Initializer in C# Object Initializer in C#
C# and Lambda – Filter elements from object collection using Where method
Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the where clause using Lambda in C#. This sample gets all the employees who salary is greater than 20000 GBP. How to Filter Employees List whose salary is greater than 20000 GBP using Lambda in C# ? Output Employees whose salary is greater than 20000 pounds Michael John
C# and LINQ – Filter elements from object collection with Logical Operators
Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the where clause using LINQ in C#. This sample gets all the employees who salary is greater than 20000 GBP and age is greater than 22. How to Filter Employees List whose salary is greater than 20000 GBP and age is greater than 22 using LINQ in C# ?…
Using String.Format method in C# to add commas in thousands place for a Number
If you need to add a comma in the thousands place for a number using the String.Format method in C# , you can use the format specifier N as shown in the below code snippet. Using String.Format method in C# to add commas in thousands place for a Number
C# Program to swap two numbers without using temporary variable
Problem Write a program in Visual CSharp to swap two numbers using temporary variable and display the result in the console window. How to swap two numbers in C# without using temporary variable ? Output Abundantcode.com coding sample Enter the First Number : 45 Enter the Second Number : 67 First Number is 67 Second Number is 45
Auto-Property Initializers with Method Call in C# 6.0
The Auto-Property Initializer in C# 6.0 is a feature that lets the users to initialize the value of the auto implemented property . This feature lets the user provide any expression (lambda expression or a method) . Auto-Property Initializers with Method Call in C# 6.0 The below code snippet demonstrates how to initialize the auto property with a method call.
Example of Composite Anonymous Types in C#
The feature of anonymous types can be felt specially when we work with the composite type rather than the simple types. The below example is more like you are defining an inline class without actually having the definition. Example of Composite Anonymous Types in C# Below is an example of the anonymous type in C# that demonstrates the composite anonymous type. Note that you will…
How to change Language Version from C# 6.0 in Visual Studio 2015 ?
There are times when you are developing .NET Project in Visual Studio 2015 with C# 6.0 enabled and you might also have members in your team using Visual Studio 2013 and still want to build and run the project. How to change Language Version from C# 6.0 in Visual Studio 2015 ? You can change the C# language version from the project properties. In the…
How to perform Shallow Copy in C# ?
To perform Shallow copy in C# , you can use the this.MemberwiseClone() method. How to perform Shallow Copy in C# ? Below is a sample code snippet that contains a method ShallowCopy to make a copy of the object.
Example of Anonymous methods in C#
Anonymous methods in C# are like regular methods nut does not contain any name. Anonymous methods are just like regular methods and uses the delegate keyword and does not need a name , parameter or return type. Example of Anonymous methods in C# Below is a sample code snippet demonstrating the usage of the anonymous types in C#
How to populate XDocument from a String in C# ?
Want to load or populate XDocument from a string in C# ? . Use the Parse method defined in the XDocument class as demonstrated below. How to populate XDocument from a String in C# ?
Initialize int array in C# ?
Here’s a code snippet demonstrating how to initialize int arrays in C# and display the contents of it using the for loop. How to Initialize int array in C# ?
Auto-Property Initializers for Read-Only Properties in C# 6.0
In the earlier version of C# , if you want a read-only property , you would end up having a backing field which is initialized in the constructor. In C# 6.0 , the auto-implemented properties can be used to implement read-only property using the auto-property initializer as shown below. Auto-Property Initializers for Read-Only Properties in C# 6.0
How to Convert byte[] to hex string in C# ?
To convert a byte array to hexadecimal string, you can use the BitConverter class in C#. How to Convert byte[] to hex string in C# ? Below is a sample code snippet demonstrating how to achieve this.