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 852 of 2547
C# program to find IP Address of the client
To find the IP address of the client machine in C#, we use the DNS (Domain Name System) class from the System.Net namespace. This involves getting the hostname first and then resolving it to obtain the associated IP addresses. Syntax Following is the syntax to get the hostname − string hostName = Dns.GetHostName(); Following is the syntax to get IP addresses from hostname − IPHostEntry hostEntry = Dns.GetHostEntry(hostName); IPAddress[] addresses = hostEntry.AddressList; How It Works The process involves two main steps: Dns.GetHostName() retrieves the hostname of the ...
Read MoreEnvironment.NewLine in C#
The Environment.NewLine property in C# provides a platform-independent way to add line breaks in strings. It automatically returns the appropriate newline character sequence for the current operating system − \r on Windows and on Unix-based systems. Using Environment.NewLine ensures your code works correctly across different platforms without hardcoding specific line break characters. Syntax Following is the syntax for using Environment.NewLine − string result = text1 + Environment.NewLine + text2; You can also use it in string concatenation or interpolation − string result = $"Line 1{Environment.NewLine}Line 2"; Basic Usage ...
Read MoreSortable ("s") Format Specifier in C#
The Sortable ("s") format specifier in C# represents a standardized date and time format that produces ISO 8601-compliant strings. This format is particularly useful for sorting dates chronologically as strings and for data interchange between different systems. The "s" format specifier is defined by the DateTimeFormatInfo.SortableDateTimePattern property and follows a consistent pattern regardless of the current culture settings. Syntax The sortable format specifier uses the following syntax − DateTime.ToString("s") This corresponds to the custom format pattern − yyyy'-'MM'-'dd'T'HH':'mm':'ss Format Pattern Breakdown Sortable Format Pattern: ...
Read MoreDecimal.Divide() Method in C#
The Decimal.Divide() method in C# is used to divide two specified Decimal values and return the quotient. This static method provides precise division operations for financial and monetary calculations where accuracy is critical. Syntax Following is the syntax − public static decimal Divide(decimal val1, decimal val2); Parameters val1 − The dividend (the number to be divided). val2 − The divisor (the number by which val1 is divided). Return Value Returns a decimal value representing the result of dividing val1 by val2. The method throws a ...
Read MoreWhat is early binding in C#?
Early binding in C# is the mechanism of linking a method call with its implementation during compile time. It is also called static binding because the method to be called is determined at compilation rather than at runtime. In early binding, the compiler knows exactly which method will be executed based on the method signature (name, parameters, and their types). This results in faster execution since no runtime resolution is needed. How Early Binding Works C# achieves early binding through static polymorphism, which includes method overloading and operator overloading. The compiler resolves which specific method to call ...
Read MoreHow to iterate over a C# list?
A List in C# is a generic collection that stores elements of the same type. There are several ways to iterate over a C# list, each with its own advantages depending on your specific needs. Syntax Following is the basic syntax for declaring and initializing a list − List listName = new List(); Following are the common iteration syntaxes − // foreach loop foreach(var item in list) { // process item } // for loop for(int i = 0; i < list.Count; i++) { // ...
Read MoreC# Linq First() Method
The First() method in C# LINQ is used to return the first element from a collection such as arrays, lists, or any IEnumerable sequence. It throws an exception if the collection is empty. Syntax Following is the syntax for the First() method − collection.First() collection.First(predicate) Parameters predicate (optional) − A function to test each element for a condition. Return Value Returns the first element in the collection or the first element that satisfies the condition. Throws InvalidOperationException if no element is found. Using First() Without Predicate The ...
Read MoreDecimal.Floor() Method in C#
The Decimal.Floor() method in C# rounds a specified decimal number down to the nearest integer toward negative infinity. This means it always rounds down, even for negative numbers. Syntax Following is the syntax − public static decimal Floor(decimal val); Parameters val − The decimal value to round down to the nearest integer. Return Value Returns a decimal value representing the largest integer less than or equal to the specified decimal number. Decimal.Floor() Behavior Number Line ...
Read MoreC# Program to Illustrate Lower Triangular Matrix
A lower triangular matrix is a square matrix where all elements above the main diagonal are zero. In other words, for any element at position (i, j), if j > i, then the element is zero. The main diagonal consists of elements where the row index equals the column index (i = j). Below the diagonal, elements can have any non-zero values. Syntax The condition to check if an element should be displayed or set to zero − if (i >= j) // Display the actual element else ...
Read MoreWhat are unary operators in C#?
Unary operators in C# are operators that operate on a single operand. They perform various operations such as incrementing, decrementing, negating, or getting the size of a data type. Complete List of Unary Operators Operator Name Description + Unary plus Indicates positive value (rarely used) - Unary minus Negates the value ! Logical NOT Inverts boolean value ~ Bitwise complement Inverts all bits ++ Increment Increases value by 1 -- Decrement Decreases value by 1 (type) Cast Converts to ...
Read More