Programming Articles

Page 839 of 2547

What is Type safe in C#?

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

Type safety in C# is a fundamental feature that prevents objects from accessing memory locations that don't belong to them. This means you cannot accidentally treat one object type as another incompatible type, which helps prevent runtime errors and memory corruption. The C# compiler enforces type safety at compile time, ensuring that operations are performed only on compatible types. This prevents common programming errors like accessing invalid memory locations or calling methods that don't exist on an object. How Type Safety Works C# prevents unsafe type conversions through compile-time checking. When you attempt to cast an object ...

Read More

C# Program to split a string on spaces

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

In C#, the Split() method is used to divide a string into an array of substrings based on a specified delimiter. When splitting a string on spaces, we use the space character ' ' as the delimiter. Syntax Following is the syntax for splitting a string on spaces − string[] result = str.Split(' '); You can also use the overloaded version with options − string[] result = str.Split(' ', StringSplitOptions.RemoveEmptyEntries); Parameters separator − The character used to split the string (space character ' ' in this case). ...

Read More

C# Program to convert an Int32 value to a decimal

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

To convert an Int32 value to a decimal in C#, you can use the Convert.ToDecimal() method or implicit casting. An Int32 represents a 32-bit signed integer, while decimal provides higher precision for financial and monetary calculations. Syntax Following is the syntax for converting Int32 to decimal using Convert.ToDecimal() − decimal result = Convert.ToDecimal(intValue); Following is the syntax for implicit casting − decimal result = intValue; Using Convert.ToDecimal() Method The Convert.ToDecimal() method explicitly converts an Int32 value to a decimal type − using System; public class Demo ...

Read More

Boolean.TryParse() Method in C#

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

The Boolean.TryParse() method in C# safely converts a string representation of a logical value to its Boolean equivalent. Unlike Boolean.Parse(), this method returns true if the conversion succeeds and false if it fails, without throwing exceptions. Syntax Following is the syntax − public static bool TryParse(string value, out bool result); Parameters value − A string containing the value to convert. result − When this method returns, contains the Boolean value equivalent to the value contained in value, if the conversion succeeded, or false if the conversion failed. ...

Read More

What is the difference between declaration and definition in C#?

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

In C#, declaration means specifying the type and name of a variable, method, or class without providing an initial value or implementation. Definition (or initialization) means providing an actual value or implementation to what was declared. This distinction applies to variables, arrays, methods, and classes. Understanding the difference helps write cleaner code and avoid compilation errors. Syntax Following is the syntax for declaration − datatype variableName; Following is the syntax for definition/initialization − variableName = value; // or combined declaration and initialization datatype variableName = value; Variable Declaration vs ...

Read More

Valid variant of Main() in C#

varun
varun
Updated on 17-Mar-2026 820 Views

The Main method is the entry point for all C# programs. It defines what the class does when executed. When you run a C# application, the runtime looks for the Main method and begins execution from there. Syntax There are several valid variants of the Main method in C# − static void Main() static void Main(string[] args) static int Main() static int Main(string[] args) Parameters static − the object is not needed to access static members. The Main method must be static so the runtime can call it without creating an ...

Read More

C# Program to split parts in a Windows directory

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 858 Views

A Windows directory path consists of multiple parts separated by backslashes (\). In C#, you can split a directory path into its individual components using the Split() method with the backslash character as the delimiter. This technique is useful for extracting specific parts of a path, validating directory structures, or processing file paths programmatically. Syntax Following is the syntax for splitting a Windows directory path − string[] parts = directoryPath.Split(''); You can also use the verbatim string literal to define the path − string path = @"C:\Users\Documents\MyFile.txt"; Using Split() ...

Read More

C# Program to convert a Byte value to an Int32 value

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

To convert a byte value to an int value in C#, you can use the Convert.ToInt32() method or implicit conversion. Since a byte (8-bit unsigned integer) can always fit within an int (32-bit signed integer), the conversion is straightforward and safe. An Int32 represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647, while a byte stores values from 0 to 255. Syntax Using Convert.ToInt32() method − int result = Convert.ToInt32(byteValue); Using implicit conversion − int result = byteValue; Using ...

Read More

Byte.CompareTo(Byte) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 203 Views

The Byte.CompareTo(Byte) method in C# is used to compare the current byte instance to a specified 8-bit unsigned integer and returns an indication of their relative values. This method is useful for sorting operations and determining the relative ordering of byte values. Syntax Following is the syntax − public int CompareTo(byte value); Parameters value: An 8-bit unsigned integer to compare with the current instance. Return Value The method returns an integer that indicates the relative values of the compared instances: Less than zero: The current instance is less ...

Read More

What are the escape sequences supported by C#?

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

Escape sequences in C# are special character combinations that start with a backslash (\) and represent characters that are difficult or impossible to type directly. These sequences allow you to include special characters like newlines, tabs, quotes, and control characters in your strings. Syntax Following is the syntax for escape sequences in C# − string text = "HelloWorld"; // represents a newline char tab = '\t'; // \t represents a tab character Common Escape Sequences ...

Read More
Showing 8381–8390 of 25,466 articles
« Prev 1 837 838 839 840 841 2547 Next »
Advertisements