TimeSpan.From methods in C# ()

Chandu yadav
Updated on 17-Mar-2026 07:04:35

229 Views

The TimeSpan.From methods in C# provide a convenient way to create TimeSpan objects from specific time units. These static methods include FromDays, FromHours, FromMinutes, FromSeconds, FromMilliseconds, and FromTicks. Each method takes a numeric value and returns a TimeSpan representing that duration in the specified unit. This approach is more readable than manually calculating ticks or using TimeSpan constructors. Syntax Following are the syntax formats for the most commonly used TimeSpan.From methods − TimeSpan.FromDays(double value) TimeSpan.FromHours(double value) TimeSpan.FromMinutes(double value) TimeSpan.FromSeconds(double value) TimeSpan.FromMilliseconds(double value) TimeSpan.FromTicks(long value) Parameters All TimeSpan.From methods (except FromTicks) accept a ... Read More

What are Booleans types in C#?

Arjun Thakur
Updated on 17-Mar-2026 07:04:35

241 Views

The bool type in C# represents Boolean values and can store only two possible values: true and false. The bool keyword is an alias for the System.Boolean structure in the .NET framework. Boolean variables are commonly used in conditional statements, loops, and logical operations to control program flow based on true/false conditions. Syntax Following is the syntax for declaring Boolean variables − bool variableName = true; // or false bool variableName; // defaults to false Basic Boolean Declaration and Assignment Example ... Read More

Byte.ToString() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

115 Views

The Byte.ToString() method in C# converts the value of the current Byte object to its equivalent string representation. This method is inherited from the Object class and overridden to provide byte-specific string conversion. Syntax Following is the syntax for the basic ToString() method − public override string ToString(); The Byte class also provides overloaded versions that accept format specifiers − public string ToString(string format); public string ToString(IFormatProvider provider); public string ToString(string format, IFormatProvider provider); Using Basic ToString() Method The parameterless ToString() method converts a byte value to its decimal ... Read More

Three Different ways to calculate factorial in C#

Samual Sam
Updated on 17-Mar-2026 07:04:35

965 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
Updated on 17-Mar-2026 07:04:35

745 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
Updated on 17-Mar-2026 07:04:35

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
Updated on 17-Mar-2026 07:04:35

378 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
Updated on 17-Mar-2026 07:04:35

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
Updated on 17-Mar-2026 07:04:35

329 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
Updated on 17-Mar-2026 07:04:35

392 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

Advertisements