Articles on Trending Technologies

Technical articles with clear explanations and examples

C# program to Display Hostname and IP address

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

To find the hostname of the current machine, use the Dns.GetHostName() method in C#. This method returns the host name of the local computer as a string. To get the IP addresses, use the IPHostEntry.AddressList property which provides an array of all IP addresses associated with the hostname. Syntax Following is the syntax for getting the hostname − string hostName = Dns.GetHostName(); Following is the syntax for getting IP addresses − IPHostEntry hostEntry = Dns.GetHostEntry(hostName); IPAddress[] addresses = hostEntry.AddressList; Example The following code demonstrates how to display hostname and ...

Read More

How to initialize a tuple to an empty tuple in C#?

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

To initialize a tuple to an empty tuple in C#, you can declare a tuple variable without assigning it a value, or assign it to null. C# provides multiple ways to work with empty or uninitialized tuples depending on your specific requirements. Syntax Following are the different ways to declare an empty tuple − // Declare without initialization (default to null) Tuple myTuple; // Initialize to null explicitly Tuple myTuple = null; // Create tuple with null/default values Tuple myTuple = new Tuple(0, null); Using Uninitialized Tuple Declaration When you declare ...

Read More

C# Program to match all the digits in a string

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

To match all digits in a string, we can use regular expressions (Regex) in C#. Regular expressions provide a powerful way to search for patterns in text, including numeric values. The System.Text.RegularExpressions namespace contains the Regex class that allows us to define patterns and find matches within strings. Syntax Following is the syntax for matching digits using Regex − MatchCollection matches = Regex.Matches(inputString, @"\d+"); The regular expression pattern \d+ breaks down as follows − \d − matches any single digit (0-9) + − matches one or more consecutive occurrences ...

Read More

"." custom specifier in C#

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

The "." custom format specifier in C# adds a localized decimal separator into the output string. It determines the exact position where the decimal point will appear in the formatted numeric value. The first period in the format string determines the location of the decimal separator in the formatted value. Any additional periods are ignored and treated as literal characters. Syntax Following is the syntax for using the "." custom format specifier − number.ToString("format_with_decimal_point") String.Format("format_with_decimal_point", number) Where the format string contains a period (.) to specify decimal separator placement. How It Works ...

Read More

What is the default access for a class in C#?

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

In C#, when no access modifier is specified for a class, the default access level is internal. An internal class can be accessed from any code within the same assembly but is not accessible from other assemblies. This means that classes declared without an explicit access modifier are visible throughout the current project or assembly, but remain hidden from external assemblies that might reference your code. Syntax Following is the syntax for declaring a class with different access levels − // Default access (internal) class MyClass { } // Explicitly internal internal class MyClass ...

Read More

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
Showing 11161–11170 of 61,297 articles
Advertisements