Programming Articles

Page 110 of 2547

Final local variables in C#

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

In C#, there is no direct equivalent to Java's final keyword for local variables. However, you can achieve similar behavior using the readonly keyword for fields and implicit typing with var or const for local variables that should not change after initialization. The readonly keyword allows a field to be assigned a value only once − either at the time of declaration or in the constructor. Once assigned, it cannot be modified. Syntax Following is the syntax for declaring a readonly field − readonly dataType fieldName; For local variables that should remain constant, ...

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

C# Console.WindowLeft Property

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

The Console.WindowLeft property in C# gets or sets the leftmost position of the console window area relative to the screen buffer. This property is useful when you need to control or retrieve the horizontal position of the console window within the buffer area. Syntax Following is the syntax to get the left position of the console window − int position = Console.WindowLeft; Following is the syntax to set the left position of the console window − Console.WindowLeft = value; Return Value The property returns an int value representing the ...

Read More

Exception Propagation in C#

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

Exception propagation in C# refers to the process of how exceptions move up through the call stack when they are not handled by the current method or try-catch block. When an exception occurs, the runtime searches for an appropriate exception handler, and if none is found, the exception propagates to the calling method. How Exception Propagation Works When an exception occurs in a try block, the runtime checks the corresponding catch blocks to see if they can handle the exception. If no matching catch block is found, the exception propagates to a higher-level try block or to the ...

Read More

Int32.GetTypeCode Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 173 Views

The Int32.GetTypeCode() method in C# returns the TypeCode enumeration value for the Int32 data type. This method is inherited from the IConvertible interface and is useful for type identification and runtime type checking operations. Syntax Following is the syntax − public TypeCode GetTypeCode(); Return Value This method returns TypeCode.Int32 for all int values, regardless of their actual numeric value. Using GetTypeCode() for Type Identification Example Let us see an example to implement the Int32.GetTypeCode() method − using System; public class Demo { public ...

Read More

Int16.CompareTo() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 6K+ Views

The Int16.CompareTo() method in C# is used to compare a 16-bit signed integer (short) with another value and returns an integer that indicates their relative order. This method is essential for sorting operations and determining the relationship between two Int16 values. Syntax The Int16.CompareTo() method has two overloads − public int CompareTo(short value); public int CompareTo(object value); Parameters value − A 16-bit signed integer or an object to compare with the current instance. Return Value The method returns an integer with the following meaning − ...

Read More

C# Program to replace a character with asterisks in a sentence

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

The Replace() method in C# is used to replace all occurrences of a specified character or string with another character or string. This method is particularly useful when you need to replace special characters like asterisks with other characters in a sentence. Syntax Following is the syntax for replacing a character using the Replace() method − string newString = originalString.Replace(oldChar, newChar); For replacing a string with another string − string newString = originalString.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

Append to StringBuilder in C#

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

The Append() method in C# is used to add content to a StringBuilder object. Unlike strings, which are immutable, StringBuilder allows efficient concatenation of text without creating new string objects in memory. StringBuilder is particularly useful when you need to perform multiple string concatenations, as it provides better performance than using the + operator repeatedly. Syntax Following is the syntax for creating a StringBuilder and using the Append() method − StringBuilder sb = new StringBuilder(); sb.Append(value); The Append() method can accept various data types including string, char, int, double, and others. It returns ...

Read More

C# difference in milliseconds between two DateTime

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

In C# programming, you often need to calculate the time difference between two DateTime objects. The most efficient way to get the difference in milliseconds is by using the TimeSpan structure and its TotalMilliseconds property. Syntax Following is the syntax for calculating milliseconds difference between two DateTime objects − 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 milliseconds = difference.TotalMilliseconds; Using TimeSpan to Calculate Milliseconds Difference When you subtract one DateTime from another, the ...

Read More
Showing 1091–1100 of 25,467 articles
« Prev 1 108 109 110 111 112 2547 Next »
Advertisements