Tag: csharp

How to Get the Top 5 elements from a List in C# ?

If you want to get the top 5 elements from a list in C# or skip the first item and get the next five elements from a List , you can use the Take and the Skip methods. How to Get the Top 5 elements from a List in C# ? Below is a sample code snippet demonstrating the usage of the Skip and Take…

C#.NET Interview Questions and Answers – Part 3

C#.NET Interview Questions and Answers – Part 3 21. What is the use of Nan values for double and float in C# ? Nan in C# is generally used to represent special values in .NET . For example , in Silverlight and WPF , the values double.Nan is generally used to represent the automatic values. 22. What is the difference between Double and decimal in…

How to get the Number of Elements in an MultiDimensional Array in C# ?

In one of the previous articles , we demonstrated the usage of the Length property of the array in C# to get the number of elements in it. In this post , lets have a look at getting the number of elements in the multi-dimentional array in C#. How to get the Number of Elements in an MultiDimensional Array in C# ? If you wanted…

Anonymous Types are read-only in C#

If you try to set a value to the anonymous type in C# , you will receive an compiler error . The properties within the anonymous types are read-only properties. Anonymous Types are read-only in C# In the above code snippet , you will receive an compiler error “Error    CS0200    Property or indexer ‘<anonymous type: string FirstName, string Last>.FirstName’ cannot be assigned to — it…

How to Get the Device Platform in Windows 10 App ?

If you running your App on Windows 10 , you might want to get the device platform from your app for some reasons. If this is the case , you can use the DeviceFamily property defined in the Windows.System.Profile.AnalyticsInfo.VersionInfo class. Below is the sample code snippet demonstrating the usage of this. How to Get the Device Platform in Windows 10 App ? The complete codebehind…

How to use array Rank in C# ?

In C# , the Rank property of the array is is used to get the rank of the array. In simple terms , rank refers to the number of dimensions of the array. How to use array Rank in C# ? You can get the number of dimensions of the array using the Rank property of the array. For instance , the Rank property of…

Pass by Reference using ref keyword

You can use the keyword ref in csharp to pass a value by reference instead of call by value . using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Namespace1 { class Student { public string StudentName { get; set; } /* usage of the pass by reference using the keyword ref */ public void Add(ref int i) { i = i +…

How to Compare two arrays in C# ?

Two arrays can be compared in C# using the Enumerable.SequenceEqual method . The Enumerable.SequenceEqual method in C# returns a boolean value indicating if both the arrays are equal or not. How to Compare two arrays in C# ? Below is an example of comparison of two arrays in C# using the Enumerable.SequenceEqual method.

C# and LINQ – Filter elements from object collection using where clause

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. How to Filter Employees List whose salary is greater than 20000 GBP using LINQ in C# ? Output Employees whose salary is greater than 20000 pounds Michael John

How to update the value in a Dictionary in C# ?

Below is a sample code snippet demonstrating how to update the value that is stored within the dictionary using C#. We access the dictionary with the key as index and set the value. How to update the value in a Dictionary in C# ?

How to get the IP Address of the Local Machine using C# ?

You can get the IP address of the local machine or localhost using C# using the Dns class’s GetHostByName defined in the System.Net namespace. The Dns.GetHostByName returns the array of AddressList which contains the IP address . How to get the IP Address of the Local Machine using C# ? Below is the sample code snippet demonstrating the retrieval of the IP address of the…

How to get the Number of Elements in an Array in C# ?

You can use the Length property of the array to return the number of elements in it. Note that once the array is created , you cannot change its length. How to get the Number of Elements in an Array in C# ? Here’s a code snippet demonstrating the usage of the Length property of the array to get the number of elements.

How to sort an array in C# ?

If you want to sort an array in C#.NET , you can use the Array.Sort method to do it. How to sort an array in C# ? Below is a sample code snippet demonstrating the usage of the Array.Sort method to sort an array in C#.