karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 15 of 143

C# Program to count the number of lines in a file

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

Counting the number of lines in a file is a common task in C# programming. This can be accomplished using several methods from the System.IO namespace. The most straightforward approach is to use the File.ReadAllLines() method combined with the Length property. Using File.ReadAllLines() Method The File.ReadAllLines() method reads all lines from a file into a string array, and then we can use the Length property to count the total number of lines − Example using System; using System.IO; public class Program { public static void Main() { ...

Read More

C# Program to Check Whether the Entered Number is an Armstrong Number or Not

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

An Armstrong number (also called a narcissistic number) is a number that equals the sum of its digits raised to the power of the number of digits. For a 3-digit number, each digit is cubed and summed. For example, 153 is an Armstrong number because − 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 Armstrong Number Check Process 153 Original Number 1³ + 5³ + 3³ Sum of Cubes ...

Read More

What is method hiding in C#?

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

Method hiding (also known as shadowing) in C# occurs when a derived class defines a method with the same name as a method in its base class, but without using the override keyword. The child class creates its own version of the method that hides the parent class method rather than overriding it. Method hiding uses the new keyword to explicitly indicate that the method is intended to hide the base class method. This is different from method overriding, which uses override and creates polymorphic behavior. Syntax Following is the syntax for method hiding using the new ...

Read More

C# Program to check whether a directory exists or not

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

The Directory.Exists method in C# is used to check whether a specified directory exists on the file system. This method returns a boolean value − true if the directory exists, and false if it does not. This functionality is essential for file system operations where you need to verify directory existence before performing operations like reading files, creating subdirectories, or moving content. Syntax Following is the syntax for the Directory.Exists method − public static bool Exists(string path) Parameters path − A string representing the path to the directory to check. ...

Read More

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
Showing 141–150 of 1,421 articles
« Prev 1 13 14 15 16 17 143 Next »
Advertisements