Programming Articles

Page 849 of 2547

Retrieve data value as a pointer in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 968 Views

A pointer is a variable whose value is the address of another variable. In C#, pointers can only be used in unsafe contexts. To retrieve the data stored at the location referenced by the pointer variable, you can use the dereference operator * or call the ToString() method on the pointer. Syntax Following is the syntax for declaring and using pointers in C# − unsafe { int* ptr = &variable; // Declare pointer and get address int value = *ptr; ...

Read More

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

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

In C#, there are several ways to initialize a string to an empty string. Understanding the different approaches helps you choose the most appropriate method for your specific use case. Syntax Following are the different ways to initialize a string to an empty string − string myStr = ""; // Empty string literal string myStr = string.Empty; // Using string.Empty property string myStr = null; // Null reference (not ...

Read More

C# Program to generate random lowercase letter

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

In C#, you can generate a random lowercase letter using the Random class and ASCII character conversion. This technique generates a random number between 0 and 25, then converts it to a corresponding lowercase letter from 'a' to 'z'. Syntax Following is the syntax for generating a random lowercase letter − Random random = new Random(); int randomIndex = random.Next(0, 26); char randomLetter = (char)('a' + randomIndex); How It Works The process involves three key steps: Generate random number: random.Next(0, 26) produces a number from 0 to 25 ...

Read More

C# Program to find a key in Dictionary

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

In C#, a Dictionary is a collection that stores key-value pairs. To check if a specific key exists in a Dictionary, you can use the ContainsKey() method, which returns true if the key is found and false otherwise. Syntax Following is the syntax for using the ContainsKey() method − bool result = dictionary.ContainsKey(key); Parameters key − The key to locate in the Dictionary. Return Value Returns true if the Dictionary contains an element with the specified key; otherwise, false. Using ContainsKey() Method The most straightforward way to ...

Read More

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

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

The Convert.ToChar(String, IFormatProvider) method in C# converts the first character of a specified string to a Unicode character. This method uses culture-specific formatting information, though the IFormatProvider parameter is ignored for string-to-char conversion since character conversion doesn't depend on culture. Syntax Following is the syntax − public static char ToChar(string val, IFormatProvider provider); Parameters val − A string of length 1 or null. provider − An object that supplies culture-specific formatting information. This parameter is ignored for string-to-char conversion. Return Value Returns a Unicode character ...

Read More

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 457 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 271 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 1K+ 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
Showing 8481–8490 of 25,466 articles
« Prev 1 847 848 849 850 851 2547 Next »
Advertisements