Programming Articles

Page 855 of 2547

What is a copy constructor in C#?

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

A copy constructor in C# creates a new object by copying variables from another object of the same class. It provides a way to initialize a new object with the values of an existing object, creating a separate copy rather than a reference to the original object. Syntax Following is the syntax for creating a copy constructor − public ClassName(ClassName obj) { this.field1 = obj.field1; this.field2 = obj.field2; // copy other fields } How Copy Constructor Works A copy constructor takes an object of ...

Read More

Convert.ChangeType Method in C#

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

The Convert.ChangeType() method in C# converts a value to a specified type. It returns an object of the target type whose value is equivalent to the original object. This method is particularly useful when you need to perform type conversions at runtime or when working with generic code. Syntax Following is the syntax for the Convert.ChangeType() method − public static object ChangeType(object value, Type conversionType) public static object ChangeType(object value, TypeCode typeCode) Parameters value − The object to convert. conversionType − The target Type to convert to. typeCode − The TypeCode representing ...

Read More

Convert.ToBoolean Method in C#

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

The Convert.ToBoolean method in C# converts a specified value to an equivalent Boolean value. This method follows specific rules depending on the input type − numeric types return false if zero, true otherwise; string values are parsed based on their content. Syntax Following is the syntax for the Convert.ToBoolean method − public static bool ToBoolean(object value); public static bool ToBoolean(string value); public static bool ToBoolean(int value); public static bool ToBoolean(double value); // Other overloads for different data types Parameters value − The value to convert to a Boolean. Can be a ...

Read More

Convert.ToByte Method in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 1K+ Views

The Convert.ToByte method in C# converts a specified value to an 8-bit unsigned integer (byte). A byte can hold values from 0 to 255, making it useful for representing small integers, ASCII characters, and binary data. This method provides a safe way to convert various data types to byte values, with built-in overflow checking that throws an OverflowException if the value is outside the valid byte range. Syntax Following are the common overloads of the Convert.ToByte method − Convert.ToByte(object value) Convert.ToByte(string value) Convert.ToByte(char value) Convert.ToByte(int value) Convert.ToByte(double value) Parameters value − ...

Read More

C# program to find the maximum of three numbers

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

Finding the maximum of three numbers is a fundamental programming problem that demonstrates conditional logic and comparison operations. This can be achieved using nested if-else statements to compare the numbers systematically. Logic The algorithm compares numbers in pairs − First, compare num1 with num2 If num1 is greater, compare num1 with num3 If num2 is greater than num1, compare num2 with num3 The winner of each comparison is the maximum Finding Maximum Logic Flow num1 num2 ...

Read More

What is finally statement in C#?

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

The finally statement in C# is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed whether an exception is raised or not. The error handling blocks are implemented using the try, catch, and finally keywords. The finally block is guaranteed to execute, making it ideal for cleanup operations like closing files, database connections, or releasing resources. Syntax Following is the syntax for the finally statement − try { // code that might throw an ...

Read More

Convert.ToUInt64 Method in C#

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

The Convert.ToUInt64() method in C# converts a specified value to a 64-bit unsigned integer (ulong). This method accepts various data types and returns their equivalent ulong representation. Syntax Following is the syntax for the Convert.ToUInt64() method − public static ulong ToUInt64(object value) public static ulong ToUInt64(string value) public static ulong ToUInt64(char value) public static ulong ToUInt64(int value) public static ulong ToUInt64(double value) Parameters value − The value to convert. Can be of type object, string, char, numeric types, or other convertible types. Return Value Returns a 64-bit ...

Read More

What does Array.IsFixedSize property of array class do in C# ?

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

The IsFixedSize property of the ArrayList class is used to determine whether an ArrayList has a fixed size. When IsFixedSize returns true, you cannot add or remove elements, but you can still modify existing elements. When it returns false, the ArrayList can grow or shrink dynamically. Regular ArrayLists created with the default constructor always return false for IsFixedSize because they can dynamically resize. However, you can create fixed-size wrappers using ArrayList.FixedSize() method. Syntax Following is the syntax to check the IsFixedSize property − bool isFixed = arrayList.IsFixedSize; Following is the syntax to create ...

Read More

C# Linq Last() Method

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

The LINQ Last() method in C# returns the last element from a sequence. It throws an exception if the sequence is empty, making it suitable when you are certain the collection contains elements. Syntax Following is the syntax for the Last() method − public static TSource Last(this IEnumerable source); public static TSource Last(this IEnumerable source, Func predicate); Parameters source − The sequence to return the last element from. predicate − (Optional) A function to test each element for a condition. Return Value Returns the last ...

Read More

Class and Static Variables in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 9K+ Views

In C#, static variables belong to the class itself rather than to any specific instance of the class. They are shared among all instances of the class and can be accessed using the class name without creating an object. Class variables (instance variables) belong to individual objects and each instance has its own copy of these variables. Static Variables Static variables are declared using the static keyword and are useful for defining constants or shared data across all instances of a class. Syntax public static dataType variableName; Static vs ...

Read More
Showing 8541–8550 of 25,466 articles
« Prev 1 853 854 855 856 857 2547 Next »
Advertisements