Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 879 of 2547
C# Program to display the first element from an array
In C#, there are multiple ways to access the first element from an array. The most common approaches include using array indexing, the First() LINQ method, and the Take() method. Syntax Following is the syntax for accessing the first element using array indexing − dataType firstElement = arrayName[0]; Following is the syntax using the LINQ First() method − dataType firstElement = arrayName.First(); Using Array Indexing The simplest and most efficient way to get the first element is using zero-based indexing − using System; class Demo { ...
Read MoreCoupling in C#
Coupling in C# refers to the degree of interdependence between classes or modules in a software system. It measures how closely connected different parts of your code are to each other. Understanding coupling is crucial for writing maintainable and flexible applications. There are two main types of coupling − tight coupling and loose coupling. The goal in good software design is to achieve loose coupling while maintaining high cohesion. Tight Coupling In tight coupling, classes are highly dependent on each other. When one class changes, it directly affects other classes, making the code difficult to maintain and ...
Read MoreDateTimeOffset.FromUnixTimeMilliseconds() Method in C#
The DateTimeOffset.FromUnixTimeMilliseconds() method in C# is used to convert a Unix timestamp expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z (Unix epoch) to a DateTimeOffset value. Unix timestamps are commonly used in web APIs, databases, and cross-platform applications as a standard way to represent time. This method provides an easy conversion from the Unix millisecond format to C#'s DateTimeOffset structure. Syntax Following is the syntax for the method − public static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds); Parameters milliseconds − A long value representing the number of milliseconds that have elapsed ...
Read MoreDecimal Functions in C#
The decimal data type in C# provides built-in methods for performing mathematical operations and comparisons on decimal values. These methods are essential for financial calculations and applications requiring high precision arithmetic. Common Decimal Methods Method Description Add(Decimal, Decimal) Adds two specified Decimal values. Ceiling(Decimal) Returns the smallest integral value that is greater than or equal to the specified decimal number. Compare(Decimal, Decimal) Compares two specified Decimal values. CompareTo(Decimal) Compares this instance to a specified Decimal object and returns a comparison of their relative values. ...
Read MoreDateTimeOffset.FromUnixTimeSeconds() Method in C#
The DateTimeOffset.FromUnixTimeSeconds() method in C# is used to convert a Unix timestamp (expressed as seconds since January 1, 1970, 00:00:00 UTC) to a DateTimeOffset value. This method is particularly useful when working with Unix-based systems or APIs that return timestamps in Unix format. Syntax Following is the syntax − public static DateTimeOffset FromUnixTimeSeconds(long seconds); Parameters seconds: A Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). This parameter accepts both positive and negative values. Return Value Returns a DateTimeOffset object ...
Read MoreWhat does the interface IList do in C#?
The IList interface in C# represents a non-generic collection of objects that can be individually accessed by index. It provides indexed access to elements, allowing you to retrieve, modify, add, and remove items at specific positions within the collection. The IList interface combines the functionality of ICollection and IEnumerable, making it suitable for collections that need both indexed access and dynamic resizing capabilities. Syntax Following is the syntax for declaring an IList variable − IList list = new ArrayList(); IList list = new List(); Following is the syntax for accessing elements by index ...
Read MoreWhat is the System.Reflection.Module in C#?
The System.Reflection.Module class in C# represents a module, which is a portable executable file containing one or more classes and interfaces. It is part of the System.Reflection namespace that allows you to examine and manipulate metadata about types, assemblies, and modules at runtime. A module is essentially a single file within an assembly. Most .NET applications consist of a single module that matches the assembly, but complex applications can have multiple modules within one assembly. Key Properties and Methods The Module class provides several important properties and methods for reflection − Assembly − Gets the ...
Read MoreC# program to print duplicates from a list of integers
To print duplicates from a list of integers in C#, you can use several approaches. The most common method involves using a Dictionary to count occurrences of each element, then filtering elements that appear more than once. Using Dictionary with ContainsKey This approach uses a Dictionary to store each number and its count. The ContainsKey method checks if a number already exists in the dictionary − using System; using System.Collections.Generic; class Program { public static void Main() { int[] arr = { 3, ...
Read MoreExit Methods in C# Application
In C# applications, there are several methods to exit or terminate the application. Each method serves different purposes and has specific use cases. Understanding when and how to use each exit method is crucial for proper application lifecycle management. Environment.Exit() Method The Environment.Exit() method terminates the entire process and returns an exit code to the operating system. This is the most common way to exit a console application. Syntax Environment.Exit(exitCode); The exitCode parameter indicates the success or failure status − 0 − Indicates successful completion Non-zero values − ...
Read MoreReturn the total elements in a sequence as a 64-bit signed integer in C#
The LongCount() method in C# returns the total number of elements in a sequence as a 64-bit signed integer (long). This method is particularly useful when dealing with large datasets where the element count might exceed the range of a regular 32-bit integer. The LongCount() method is available in both LINQ to Objects and LINQ to Entities, and can be used with any IEnumerable or IQueryable collection. Syntax Following is the syntax for using LongCount() method − public static long LongCount(this IEnumerable source) public static long LongCount(this IEnumerable source, Func predicate) Parameters ...
Read More