Programming Articles

Page 878 of 2547

Counters in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

Counters in C# are performance counters that allow you to monitor your application's performance metrics in real-time. These counters provide valuable insights into system resources, application behavior, and overall performance characteristics. When building applications — whether web, mobile, or desktop — monitoring performance is crucial for identifying bottlenecks, optimizing resource usage, and ensuring smooth operation under various load conditions. Syntax Following is the syntax for creating a performance counter − PerformanceCounter counter = new PerformanceCounter(categoryName, counterName, instanceName); Following is the syntax for reading counter values − float value = counter.NextValue(); ...

Read More

What are postfix operators in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

The postfix operators in C# are the increment (++) and decrement (--) operators that are placed after the variable. With postfix operators, the current value of the variable is returned first, and then the variable is incremented or decremented by 1. Syntax Following is the syntax for postfix increment and decrement operators − variable++; // postfix increment variable--; // postfix decrement How Postfix Operators Work The key behavior of postfix operators is that they return the original value before performing the increment or decrement operation. This is different from prefix operators ...

Read More

How to find a matching substring using regular expression in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

Regular expressions in C# provide a powerful way to search for specific patterns within strings. The Regex.Matches() method from the System.Text.RegularExpressions namespace allows you to find all occurrences of a pattern in a string. To find a matching substring, you create a regex pattern and use it to search through your target string. The pattern can be a simple literal match or include special regex metacharacters for more complex searches. Syntax Following is the basic syntax for finding matches using regular expressions − MatchCollection matches = Regex.Matches(inputString, pattern); For word boundary matching, use ...

Read More

Swapping Characters of a String in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

Swapping characters in a string involves replacing specific characters with their counterparts while preserving the original structure. In C#, this can be accomplished using various approaches including the Select method with LINQ, character arrays, or the Replace method. Syntax Following is the syntax for swapping characters using LINQ's Select method − string.Select(character => condition ? replacement : character).ToArray() Following is the syntax for swapping using character arrays − char[] charArray = string.ToCharArray(); // modify charArray elements new string(charArray) Using LINQ Select Method The Select method processes each character individually ...

Read More

Convert Decimal to Int64 (long) in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 8K+ Views

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 More

Database Operations in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

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 More

DateTimeOffset.FromFileTime() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 97 Views

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 More

What does the interface ICollection do in C#

George John
George John
Updated on 17-Mar-2026 3K+ Views

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 More

Formatted output in C#

George John
George John
Updated on 17-Mar-2026 2K+ Views

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 More

How to set a value to the element at the specified position in the one-dimensional array in C#

radhakrishna
radhakrishna
Updated on 17-Mar-2026 407 Views

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 More
Showing 8771–8780 of 25,466 articles
« Prev 1 876 877 878 879 880 2547 Next »
Advertisements