Programming Articles

Page 850 of 2547

How to get last 4 characters from string innC#?

radhakrishna
radhakrishna
Updated on 17-Mar-2026 3K+ Views

Getting the last 4 characters from a string in C# is a common task that can be accomplished using the Substring() method. This method extracts a portion of the string based on the starting position and length specified. Syntax Following is the syntax for using Substring() to get the last characters − string.Substring(startIndex) string.Substring(startIndex, length) To get the last 4 characters, calculate the starting position as − str.Substring(str.Length - 4) Using Substring() Method The Substring() method extracts characters from a specified starting position to the end of the string. ...

Read More

Convert.ToDateTime(String, IFormatProvider) Method in C#

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

The Convert.ToDateTime(String, IFormatProvider) method in C# converts a string representation of a date and time to an equivalent DateTime object, using the specified culture-specific formatting information. This method is particularly useful when working with date strings from different cultures or regions, as it allows you to specify how the date should be interpreted based on cultural formatting conventions. Syntax Following is the syntax − public static DateTime ToDateTime(string value, IFormatProvider provider); Parameters value − A string that contains a date and time to convert. provider − An object ...

Read More

C# program to replace all spaces in a string with '%20'

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

When working with strings in C#, you may need to replace spaces with '%20' for URL encoding or other formatting purposes. The Replace() method provides a simple way to substitute all occurrences of a character or substring with another value. Syntax Following is the syntax for using the Replace() method − string newString = originalString.Replace(oldValue, newValue); Parameters oldValue − The string or character to be replaced newValue − The string or character to replace with Return Value The method returns a new string with all occurrences of the specified ...

Read More

What is run time polymorphism in C#?

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

Runtime polymorphism in C# allows the same method call to behave differently depending on the actual type of object at runtime. This is achieved through method overriding, also known as dynamic binding or late binding. It is implemented using abstract classes and virtual functions. In runtime polymorphism, the method to be called is determined at runtime based on the object's actual type, not the reference type declared at compile time. Runtime Polymorphism Flow Base Class Circle Rectangle ...

Read More

How to insert an item in a list at a given position in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 3K+ Views

To insert an item in an already created List, use the Insert() method. This method allows you to insert an element at a specific index position within the list, shifting all subsequent elements to the right. Syntax Following is the syntax for the Insert() method − list.Insert(index, item); Parameters index − The zero-based index at which the item should be inserted. item − The object to insert into the list. Insert Operation at Index 3 Before Insert: ...

Read More

Replace parts of a string with C# Regex

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

Regular expressions (Regex) in C# provide powerful pattern matching and string replacement capabilities. The Regex.Replace() method allows you to replace parts of a string that match a specified pattern with a replacement string. Syntax Following is the syntax for using Regex.Replace() method − Regex.Replace(input, pattern, replacement); Parameters input − The string to search for a match pattern − The regular expression pattern to match replacement − The replacement string Return Value Returns a new string where all matches of the pattern are replaced with the replacement string. If no ...

Read More

Size of a Three-dimensional array in C#

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

To get the size of a three-dimensional array in C#, you can use the GetLength() method to retrieve the size of individual dimensions, or the Length property to get the total number of elements across all dimensions. Syntax Following is the syntax for getting the size of specific dimensions − array.GetLength(dimensionIndex) Following is the syntax for getting the total number of elements − array.Length Parameters dimensionIndex − A zero-based integer representing the dimension index (0 for first dimension, 1 for second dimension, 2 for third dimension). ...

Read More

What is the difference between a class and an object in C#?

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

When you define a class, you define a blueprint or template for a data type. The object is an instance of that class − a concrete implementation created from the blueprint. A class defines the structure and behavior, while objects are the actual entities that hold data and perform actions. The methods and variables that constitute a class are called members of the class. To access class members, you use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member. Class vs Object ...

Read More

FormatException in C#

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

A FormatException is thrown when the format of an argument is invalid or cannot be converted to the expected data type. This commonly occurs when attempting to parse a string that doesn't match the expected format for numeric or date types. Common Scenarios FormatException typically occurs in these situations − Parsing a non-numeric string as a number using int.Parse(), double.Parse(), etc. Converting a string with decimal points to an integer Parsing invalid date formats using DateTime.Parse() Using incorrect format specifiers in string formatting Using int.Parse() with ...

Read More

Convert.ToDecimal(String, IFormatProvider) Method in C#

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

The Convert.ToDecimal(String, IFormatProvider) method in C# converts the specified string representation of a number to an equivalent decimal number, using the specified culture-specific formatting information. This overload is particularly useful when dealing with different number formats across various cultures and locales. Syntax Following is the syntax − public static decimal ToDecimal(string value, IFormatProvider provider); Parameters value − A string that contains a number to convert. provider − An object that supplies culture-specific formatting information. If null, the current thread culture is used. Return Value Returns a decimal number that ...

Read More
Showing 8491–8500 of 25,466 articles
« Prev 1 848 849 850 851 852 2547 Next »
Advertisements