Programming Articles

Page 813 of 2547

Three Different ways to calculate factorial in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 933 Views

The factorial of a number is the product of all positive integers less than or equal to that number. For example, factorial of 5 (written as 5!) is 5 × 4 × 3 × 2 × 1 = 120. In C#, you can calculate factorial using three different approaches − Syntax The mathematical definition of factorial is − n! = n × (n-1) × (n-2) × ... × 2 × 1 0! = 1 (by definition) 1! = 1 Factorial Calculation Methods For Loop ...

Read More

C# Program to Add Two TimeSpan

George John
George John
Updated on 17-Mar-2026 741 Views

The TimeSpan structure in C# represents a time interval and provides methods to perform arithmetic operations. You can add two TimeSpan objects using the Add() method or the + operator to get the combined duration. Syntax Following is the syntax for adding two TimeSpan objects using the Add() method − TimeSpan result = timespan1.Add(timespan2); You can also use the + operator for addition − TimeSpan result = timespan1 + timespan2; Using the Add() Method The Add() method returns a new TimeSpan that represents the sum of two time intervals ...

Read More

Convert.ToDouble Method in C#

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

The Convert.ToDouble() method in C# converts a specified value to a double-precision floating-point number. This method is part of the Convert class and can handle various data types including integers, strings, booleans, and other numeric types. Syntax Following is the syntax for the Convert.ToDouble() method − public static double ToDouble(object value) public static double ToDouble(string value) public static double ToDouble(int value) public static double ToDouble(long value) public static double ToDouble(bool value) Parameters value − The value to be converted to a double-precision floating-point number. This can be of various types including object, string, ...

Read More

try keyword in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 374 Views

The try keyword in C# is used to define a block of code that might throw an exception. It must be followed by one or more catch blocks to handle exceptions, and optionally a finally block for cleanup code that runs regardless of whether an exception occurs. Syntax Following is the basic syntax for a try-catch block − try { // code that might throw an exception } catch (ExceptionType e) { // exception handling code } Following is the syntax with a finally block − ...

Read More

C# TicksPer constants

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 287 Views

The TicksPer constants in C# are predefined values in the TimeSpan class that represent the number of ticks for different time units. A tick is the smallest unit of time measurement in .NET, where one tick equals 100 nanoseconds. These constants help convert between ticks and common time measurements. Available TicksPer Constants The TimeSpan class provides the following TicksPer constants − TicksPerDay − Number of ticks in one day TicksPerHour − Number of ticks in one hour TicksPerMinute − Number of ticks in one minute TicksPerSecond − Number of ticks in one second TicksPerMillisecond − Number ...

Read More

ContainsKey() method in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 323 Views

The ContainsKey() method in C# is used to check whether a specific key exists in a Hashtable or other collection types like Dictionary. This method returns true if the key is found, otherwise it returns false. Syntax Following is the syntax for the ContainsKey() method − bool ContainsKey(object key) Parameters key − The key to locate in the collection. Return Value Returns true if the key exists in the collection; otherwise, false. ContainsKey() Method Logic Hashtable ...

Read More

How to use StringBuilder in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 379 Views

The StringBuilder class in C# is designed for efficient string manipulation when you need to perform multiple operations like appending, inserting, or replacing characters. Unlike regular strings, which are immutable and create new objects for every modification, StringBuilder maintains a mutable buffer that can be expanded without creating new objects in memory. Syntax Following is the syntax to initialize a StringBuilder − StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder(string value); StringBuilder sb = new StringBuilder(int capacity); StringBuilder sb = new StringBuilder(string value, int capacity); Key Advantages of StringBuilder Mutable ...

Read More

Timer in C#

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

The System.Timers.Timer class in C# generates events at specified intervals. It is useful for executing code periodically, such as updating displays, checking status, or performing background tasks. The timer can be configured to fire once or repeatedly, and provides precise control over timing intervals and event handling. Syntax Following is the syntax for creating and configuring a timer − Timer timer = new System.Timers.Timer(intervalInMilliseconds); timer.Elapsed += EventHandlerMethod; timer.Enabled = true; Following is the syntax for the event handler method − private static void EventHandlerMethod(Object source, ElapsedEventArgs e) { ...

Read More

Represent exact representation of no time in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 138 Views

The TimeSpan.Zero property in C# represents the exact representation of no time, which displays as 00:00:00. This is a static readonly field that provides a convenient way to initialize or compare TimeSpan values when you need to represent zero duration. Syntax Following is the syntax for using TimeSpan.Zero − TimeSpan timespan = TimeSpan.Zero; You can also use it for comparison operations − if (timespan == TimeSpan.Zero) { // timespan represents no time } Using TimeSpan.Zero for Initialization The most common use of TimeSpan.Zero is to initialize ...

Read More

Clear a Hashtable in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 533 Views

The Clear() method in C# is used to remove all key-value pairs from a Hashtable. This method provides an efficient way to empty the entire Hashtable in a single operation, resetting its count to zero while maintaining the original capacity. Syntax Following is the syntax for the Clear()

Read More
Showing 8121–8130 of 25,466 articles
« Prev 1 811 812 813 814 815 2547 Next »
Advertisements