karthikeya Boyini

karthikeya Boyini

1,420 Articles Published

Articles by karthikeya Boyini

Page 9 of 142

C# Percent ("P") Format Specifier

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

The percent ("P") format specifier in C# is used to format numbers as percentages. It multiplies the number by 100 and appends a percentage sign (%) to create a string representation of the percentage value. Syntax Following is the syntax for using the percent format specifier − number.ToString("P") // Default precision (2 decimal places) number.ToString("Pn") // Specify n decimal places Where n represents the number of decimal places to display after the decimal point. How It Works The percent ...

Read More

Const vs Static vs Readonly in C#

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

The const, static, and readonly keywords in C# serve different purposes for declaring fields and members. Understanding their differences is crucial for choosing the right approach based on your specific needs. Const Constant fields are compile-time constants that cannot be modified after declaration. They must be assigned a value at the time of declaration and are implicitly static. const int a = 5; Example using System; class Constants { public const int MaxValue = 100; public const string AppName = "MyApp"; public ...

Read More

C# Program to get the difference between two dates in seconds

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

In C#, you can calculate the difference between two dates in seconds using the TimeSpan structure. When you subtract one DateTime from another, it returns a TimeSpan object that represents the time interval between them. Syntax Following is the syntax for calculating date difference in seconds − DateTime date1 = new DateTime(year, month, day, hour, minute, second); DateTime date2 = new DateTime(year, month, day, hour, minute, second); TimeSpan difference = date2 - date1; double seconds = difference.TotalSeconds; Using DateTime Subtraction The most straightforward approach is to subtract one DateTime from another, which returns ...

Read More

C# Program to replace a special character from a String

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

The Replace() method in C# is used to replace all occurrences of a specified character or substring in a string with a new character or substring. This method is particularly useful for removing or replacing special characters from strings. Syntax Following is the syntax for replacing characters using the Replace() method − string.Replace(oldChar, newChar) string.Replace(oldString, newString) Parameters oldChar/oldString − The character or string to be replaced. newChar/newString − The character or string to replace with. Return Value The Replace()

Read More

How to clear screen using C#?

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

The Console.Clear() method in C# is used to clear the console screen and its buffer. When this method is called, the cursor automatically moves to the top-left corner of the console window, effectively giving you a clean slate to work with. Syntax Following is the syntax for the Console.Clear() method − Console.Clear(); How It Works The Console.Clear() method performs the following actions − Clears all text and content from the console window Resets the cursor position to (0, 0) — the top-left corner Preserves the current ...

Read More

How to copy a List collection to an array?

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

To copy a C# List collection to an array, you can use several methods. The most common approaches are the CopyTo() method, the ToArray() method, or creating an array with the List constructor. Syntax Following is the syntax for using CopyTo() method − list.CopyTo(array); list.CopyTo(array, arrayIndex); Following is the syntax for using ToArray() method − T[] array = list.ToArray(); Using CopyTo() Method The CopyTo() method copies all elements from the List to an existing array starting at the specified array index − using System; using System.Collections.Generic; ...

Read More

C# Program to check whether the elements of a sequence satisfy a condition or not

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

The All() method in C# is used to check whether all elements in a sequence satisfy a specified condition. This method returns true only if every element meets the condition; if even one element fails the condition, it returns false. The All() method is part of LINQ (Language Integrated Query) and can be used with arrays, lists, and other enumerable collections. It uses lambda expressions to define the condition that each element must satisfy. Syntax Following is the syntax for using the All() method − bool result = collection.All(predicate); Where predicate is a ...

Read More

Debug Class vs Debugger Class in C#

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

The Debug class and Debugger class in C# are both part of the System.Diagnostics namespace but serve different purposes. The Debug class provides methods for conditional debugging output, while the Debugger class enables communication and interaction with debuggers attached to your application. Debug Class The Debug class is a static class that provides conditional compilation methods for debugging. It outputs information only when the DEBUG symbol is defined during compilation − public static class Debug Properties of Debug Class Property Description AutoFlush Gets or sets a ...

Read More

Compare the content of two StringBuilders

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

The Equals method in C# is used to compare the content of two StringBuilder objects. This method performs a character-by-character comparison of the text content stored in both StringBuilder instances. Syntax Following is the syntax for comparing two StringBuilder objects − bool result = stringBuilder1.Equals(stringBuilder2); Parameters The Equals method takes one parameter − sb − The StringBuilder object to compare with the current instance. Return Value The method returns a bool value − true if both StringBuilder objects have the same content. ...

Read More

Clear a StringBuilder in C#

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

The Clear() method in C# is used to remove all characters from a StringBuilder object, effectively resetting it to an empty state. This method is efficient as it doesn't create a new object but simply resets the internal character buffer. Syntax Following is the syntax for the Clear() method − stringBuilder.Clear(); Return Value The Clear() method returns a reference to the same StringBuilder instance with all characters removed. This allows for method chaining. Using StringBuilder Clear() Method Example The following example demonstrates how to clear a StringBuilder and check its ...

Read More
Showing 81–90 of 1,420 articles
« Prev 1 7 8 9 10 11 142 Next »
Advertisements