Tag: csharp
C# Program to print the sum of two numbers
Problem Write a program in C# to add two numbers and display the result in copnsole window. How to print the sum of two numbers in C# ? Output Abundantcode.com coding sample 35
How to get the AM or PM value from a DateTime object in C# ?
There are times when you might want to get only the string AM or PM from the DateTime object that you have. How to get the AM or PM value from a DateTime object in C# ? You can get this by using the format specifiers in the ToString method as shown in the code snippet.
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 Copy the entire contents of a directory in C# ?
Below is a sample code snippets that demonstrates how to copy the entire contents of a directory to another in C#. How to Copy the entire contents of a directory in C# ?
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…
How to Get the number of elements in ArrayList in C# ?
Here’s the code that demonstrates how one can get the total number of elements contained in the ArrayList using C# using the Count property of the ArrayList. How to Get the number of elements in ArrayList in C# ?
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 Add range of elements to ArrayList in C# ?
You can use the AddRange method of the ArrayList object to add the range of elements (string array) to ArrayList in C#. How to Add range of elements to ArrayList in C# ? Here’s the code that demonstrates how to do it.
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# ?
Code Snippet to demonstrate Bitwise AND in C#
Below is a code snippet to demonstrate the Bitwise AND 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#.
C# and Lambda – 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 Lambda 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 Lambda in C# ?…