karthikeya Boyini

karthikeya Boyini

1,420 Articles Published

Articles by karthikeya Boyini

Page 20 of 142

C# Enum TryParse() Method

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

The Enum.TryParse() method in C# safely attempts to convert the string representation of one or more enumerated constants to an equivalent enumerated object. Unlike Enum.Parse(), it returns a boolean value indicating success or failure instead of throwing an exception for invalid values. Syntax Following are the overloads for the Enum.TryParse() method − public static bool TryParse(string value, out TEnum result) public static bool TryParse(string value, bool ignoreCase, out TEnum result) Parameters value − The string representation of the enumeration name or underlying value to convert. ignoreCase − A ...

Read More

C# program to count the number of words in a string

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

In C#, counting the number of words in a string can be accomplished using various approaches. The most common method involves iterating through each character and identifying word separators like spaces, tabs, and newlines. Using Character-by-Character Iteration This approach loops through the string and counts whitespace characters to determine word boundaries − using System; public class Demo { public static void Main() { int a = 0, myWord = 1; string str = "Hello World!"; if (str.Length == 0) { myWord = 0; } else { while (a

Read More

C# program to convert binary string to Integer

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

Converting a binary string to an integer in C# can be accomplished using several methods. The most straightforward approach is using Convert.ToInt32() with base 2, but you can also implement manual conversion for better understanding of the binary-to-decimal process. Using Convert.ToInt32() Method The simplest way to convert a binary string to an integer is using the built-in Convert.ToInt32() method with base 2 − using System; class Program { static void Main() { string binaryStr = "1001"; ...

Read More

What is the difference between a mutable and immutable string in C#?

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

In C#, mutable strings can be modified after creation, while immutable strings cannot be changed once created. The StringBuilder class represents mutable strings, whereas the string class represents immutable strings. When you modify an immutable string, .NET creates a new string object in memory. With mutable strings using StringBuilder, modifications are made to the existing object without creating new memory allocations. Immutable String A string in C# is immutable, meaning once created, it cannot be modified. Any operation that appears to modify a string actually creates a new string object in memory. Syntax string ...

Read More

Thread Pools in C#

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

A thread pool in C# is a collection of pre-created threads that can be reused to execute multiple tasks efficiently. Instead of creating new threads for each task, the thread pool manages a pool of worker threads, reducing the overhead of thread creation and destruction. The ThreadPool class in the System.Threading namespace provides methods to queue work items for execution by background threads. When a thread completes its task, it returns to the pool and waits for the next available work item. Syntax Following is the syntax for queuing work items to the thread pool − ...

Read More

C# Program to get the last write time of a file

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

To get the last write time of a file in C#, you can use the LastWriteTime property of the FileInfo class. This property returns a DateTime object representing when the file was last modified. You can also use the static File.GetLastWriteTime() method as an alternative approach for retrieving the last write time without creating a FileInfo instance. Syntax Using FileInfo class − FileInfo fileInfo = new FileInfo("filename.txt"); DateTime lastWrite = fileInfo.LastWriteTime; Using File.GetLastWriteTime() method − DateTime lastWrite = File.GetLastWriteTime("filename.txt"); Using FileInfo Class The FileInfo class provides comprehensive file ...

Read More

C# Queryable Take() Method

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

The Take() method in C# is a LINQ extension method that returns a specified number of contiguous elements from the start of a sequence. It's commonly used with IQueryable collections to limit the number of results returned from a query. Syntax Following is the syntax for the Take() method − public static IQueryable Take( this IQueryable source, int count ) Parameters source − The IQueryable to return elements from. count − The number of elements to return. Return Value ...

Read More

C# Program to Convert Character case

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

Converting character case in C# is a common string manipulation task. The string class provides built-in methods ToLower() and ToUpper() to convert strings to lowercase and uppercase respectively. Syntax Following is the syntax for converting string case − string.ToLower() // Converts to lowercase string.ToUpper() // Converts to uppercase Both methods return a new string with the case converted and do not modify the original string. Using ToLower() Method The ToLower() method converts all uppercase characters in a string to lowercase − using System; ...

Read More

Get the creation time of a file in C#

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

To get the creation time of a file in C#, you can use the CreationTime property of the FileInfo class or the static methods from the File class. This allows you to retrieve when a file was originally created on the file system. Syntax Using the FileInfo class − FileInfo fileInfo = new FileInfo("filename.txt"); DateTime creationTime = fileInfo.CreationTime; Using the static File class − DateTime creationTime = File.GetCreationTime("filename.txt"); Using FileInfo Class The FileInfo class provides an object-oriented approach to work with file information. Create a FileInfo object and access ...

Read More

C# Program to Convert Decimal to Binary

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

Converting a decimal number to binary involves repeatedly dividing the decimal number by 2 and collecting the remainders. In C#, this can be accomplished using manual division or built-in methods like Convert.ToString(). The manual approach uses the division by 2 method where we divide the decimal number by 2, store the remainder, and continue until the quotient becomes 0. The binary representation is formed by reading the remainders in reverse order. Using Manual Division Method This method involves dividing the decimal number by 2 repeatedly and collecting remainders − Decimal to Binary ...

Read More
Showing 191–200 of 1,420 articles
« Prev 1 18 19 20 21 22 142 Next »
Advertisements