Programming Articles

Page 830 of 2547

C# Program to write an array to a file

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

Writing an array to a file in C# can be accomplished using the File.WriteAllLines method from the System.IO namespace. This method writes each array element as a separate line to the specified file. Syntax Following is the syntax for using File.WriteAllLines − File.WriteAllLines(string path, string[] contents); Parameters path − The file path where the array will be written contents − The string array to write to the file Using WriteAllLines Method The WriteAllLines method automatically creates the file if it doesn't exist and overwrites it ...

Read More

How do we access elements from the two-dimensional array in C#?

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

A two-dimensional array in C# can be thought of as a table structure with rows and columns. Elements are accessed using two indices: the row index and the column index, separated by a comma within square brackets. Syntax Following is the syntax for accessing elements from a two-dimensional array − dataType value = arrayName[rowIndex, columnIndex]; Following is the syntax for assigning values to elements − arrayName[rowIndex, columnIndex] = value; 2D Array Structure Columns [0] [1] [2] ...

Read More

Decimal.FromOACurrency() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 123 Views

The Decimal.FromOACurrency() method in C# converts a 64-bit signed integer containing an OLE Automation Currency value to its equivalent decimal representation. OLE Automation Currency stores currency values as scaled integers, where the value is multiplied by 10, 000 to preserve four decimal places of precision. Syntax Following is the syntax for the Decimal.FromOACurrency() method − public static decimal FromOACurrency(long val); Parameters val: A 64-bit signed integer that contains an OLE Automation Currency value to be converted. Return Value Returns a decimal value equivalent to the OLE Automation Currency value. The returned ...

Read More

C# program to convert a list of characters into a string

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

Converting a list of characters into a string is a common operation in C#. There are several approaches to accomplish this task, each suitable for different scenarios and data structures. Syntax Following are the main syntax patterns for converting characters to strings − // Using string constructor with char array string result = new string(charArray); // Using string.Join() method string result = string.Join("", charList); // Using StringBuilder class StringBuilder sb = new StringBuilder(); sb.Append(charArray); string result = sb.ToString(); Using String Constructor with Character Array The most direct approach is using the ...

Read More

Why we do not have global variables in C#?

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

C# does not have global variables like those found in C or C++. Instead, C# follows an object-oriented paradigm where all data and methods must be contained within classes or structures. The global namespace alias (global::) is used to resolve naming conflicts between namespaces, not to access global variables. Why C# Doesn't Have Global Variables C# was designed with several principles that eliminate the need for global variables − Type Safety: Global variables can lead to unpredictable behavior and make debugging difficult. Object-Oriented Design: Everything must belong to a class or struct, promoting ...

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 343 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

Type.GetNestedType() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 190 Views

The Type.GetNestedType() method in C# is used to retrieve a specific nested type that is declared within the current type. This method is part of the System.Reflection namespace and provides access to nested classes, interfaces, structs, or other types defined inside a parent type. Syntax Following are the overloads for the GetNestedType() method − public Type GetNestedType(string name); public abstract Type GetNestedType(string name, System.Reflection.BindingFlags bindingAttr); Parameters name − The string containing the simple name of the nested type to get. bindingAttr − A combination of enumeration values that specify how the search ...

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
Showing 8291–8300 of 25,466 articles
« Prev 1 828 829 830 831 832 2547 Next »
Advertisements