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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Convert Decimal to Int64 (long) in C#
The Convert.ToInt64() method in C# converts a decimal value to a 64-bit signed integer (long). This conversion rounds the decimal to the nearest integer using banker's rounding (round to even) and truncates any fractional part. Syntax Following is the syntax for converting decimal to Int64 − long result = Convert.ToInt64(decimalValue); Parameters decimalValue − The decimal number to be converted to Int64. Return Value Returns a 64-bit signed integer equivalent of the specified decimal value, rounded to the nearest integer. Using Convert.ToInt64() for Basic Conversion The following example ...
Read MoreDatabase Operations in C#
Database operations in C# are typically performed using ADO.NET, which provides a set of classes to interact with various databases like SQL Server, MySQL, Oracle, and SQLite. The most common approach involves using connection strings, command objects, and data readers to execute SQL operations. Connection String Syntax A connection string contains the information needed to connect to a database − // SQL Server connection string "Data Source=serverName;Initial Catalog=databaseName;Integrated Security=true;" // SQL Server with username/password "Data Source=serverName;Initial Catalog=databaseName;User ID=username;Password=password;" Establishing Database Connection The SqlConnection class is used to establish a connection to SQL ...
Read MoreDateTimeOffset.FromFileTime() Method in C#
The DateTimeOffset.FromFileTime() method in C# converts a Windows file time value (in ticks) to an equivalent DateTimeOffset representing the local time. This method is useful when working with file timestamps or Windows-specific time representations. Syntax Following is the syntax for the DateTimeOffset.FromFileTime() method − public static DateTimeOffset FromFileTime(long fileTime); Parameters fileTime: A Windows file time expressed in ticks. This represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC). Return Value Returns a DateTimeOffset object that represents the date and ...
Read MoreWhat does the interface ICollection do in C#
The ICollection interface in C# defines the size, enumerators, and synchronization methods for all nongeneric collections. It is the base interface for classes in the System.Collections namespace and serves as the foundation for collection types like ArrayList, Hashtable, and Queue. This interface provides essential functionality that all collection classes must implement, including methods to copy elements and enumerate through the collection, along with properties to get the count and synchronization object. Syntax Following is the syntax for implementing the ICollection interface − public interface ICollection : IEnumerable { int Count { ...
Read MoreFormatted output in C#
In C#, formatted output allows you to control how data is displayed when converting values to strings. This is essential for presenting numbers, dates, and other data types in a user-friendly format using format specifiers and the String.Format() method. Syntax Following is the syntax for basic string formatting − String.Format("{index:format}", value) Where index is the parameter position (starting from 0) and format is the format specifier. Using Format Specifiers for Numbers Decimal Places and Thousands Separator using System; class Demo { public static void Main(String[] ...
Read MoreHow to set a value to the element at the specified position in the one-dimensional array in C#
In C#, you can set a value to an element at a specific position in a one-dimensional array using the array indexing operator []. Array indexing in C# is zero-based, meaning the first element is at index 0, the second at index 1, and so on. Syntax Following is the syntax for setting a value to an array element at a specified position − arrayName[index] = value; Where index is the position (starting from 0) and value is the new value to be assigned. Using Array Index Assignment First, declare and initialize ...
Read MoreC# 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 More