Programming Articles

Page 79 of 2547

C# Object Creation of Inherited Class

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

In C# inheritance, when creating objects of derived classes, the base class constructor is called first, followed by the derived class constructor. This ensures that the base class is properly initialized before the derived class adds its own functionality. The derived class inherits member variables and methods from the base class. When instantiating a derived class object, you can use the base keyword to explicitly call the base class constructor and pass required parameters. Syntax Following is the syntax for calling a base class constructor from a derived class − public class DerivedClass : BaseClass ...

Read More

Dictionary.Item[] Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 497 Views

The Dictionary.Item[] property in C# provides a convenient way to get or set values in a Dictionary using indexer syntax. This property allows you to access dictionary values directly using square bracket notation with the key, similar to array indexing. Syntax Following is the syntax for the Dictionary.Item[] property − public TValue this[TKey key] { get; set; } Parameters key − The key of the element to get or set. Return Value The property returns the value associated with the specified key. If the key is not found when ...

Read More

How to calculate Power of a number using recursion in C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

To calculate power of a number using recursion in C#, we use the mathematical principle that n^p = n × n^(p-1). The recursive function calls itself with a reduced power until it reaches the base case. Syntax Following is the syntax for a recursive power function − static long Power(int number, int power) { if (power == 0) { return 1; // base case } return number * Power(number, power - 1); // recursive ...

Read More

What is abstraction in C#?

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

Abstraction is a fundamental concept in object-oriented programming that focuses on hiding complex implementation details while showing only the essential features of an object. In C#, abstraction allows you to define what an object does without specifying how it does it. Abstraction and encapsulation work together − abstraction defines the interface and essential behavior, while encapsulation hides the internal implementation details from the outside world. Key Concepts of Abstraction Hide complexity − Users interact with simplified interfaces without knowing internal workings Focus on essential features − Only relevant methods and properties are exposed Provide common interface ...

Read More

C# Program to make a copy of an existing file

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

The File.Copy method in C# is used to copy an existing file from one location to another. This method is part of the System.IO namespace and provides a simple way to duplicate files programmatically. Syntax Following is the syntax for the File.Copy method − File.Copy(string sourceFileName, string destFileName); File.Copy(string sourceFileName, string destFileName, bool overwrite); Parameters sourceFileName − The path of the file to copy. destFileName − The path of the destination file. overwrite − Optional boolean parameter. If true, overwrites the destination file if it already exists. ...

Read More

C# Nullable Datetime

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

The nullable DateTime in C# allows you to assign null values to DateTime variables, which is useful when a date might not be available or applicable. This is particularly valuable in database operations where date fields can be NULL, or when dealing with optional date parameters. Syntax A nullable DateTime is declared using the question mark (?) syntax − DateTime? variableName = null; Alternatively, you can use the full Nullable syntax − Nullable variableName = null; Key Properties and Methods Nullable DateTime provides several useful properties and methods − ...

Read More

Dictionary.Keys Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 378 Views

The Dictionary.Keys property in C# is used to fetch all the keys in the Dictionary. This property returns a KeyCollection that contains all the keys from the dictionary, which can be iterated through using a foreach loop. Syntax Following is the syntax − public System.Collections.Generic.Dictionary.KeyCollection Keys { get; } Return Value The Keys property returns a Dictionary.KeyCollection containing all the keys in the dictionary. This collection is a live view of the keys, meaning if the dictionary changes, the collection reflects those changes. Using Dictionary.Keys Property Example Let us see ...

Read More

CopyOnWriteArrayList version in C#

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

While Java has CopyOnWriteArrayList, C# does not have a direct equivalent. Instead, the SynchronizedCollection class in C# provides thread-safe collection operations. Unlike Java's copy-on-write approach, SynchronizedCollection uses locking mechanisms to ensure thread safety. Syntax Following is the syntax for declaring a SynchronizedCollection − public class SynchronizedCollection : IList, ICollection, IEnumerable, IEnumerable, IList, ICollection Where T is the type of objects in the collection. Properties The SynchronizedCollection class provides the following key properties − Property Description Count Gets the number of ...

Read More

Delete a file in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 1K+ Views

In C#, you can use the File.Delete() method from the System.IO namespace to delete files from the file system. This method permanently removes the specified file if it exists. Syntax Following is the syntax for deleting a file − File.Delete(string path); Parameters path − A string specifying the path of the file to be deleted. This can be a relative or absolute path. Using File.Delete() Method The File.Delete() method removes the file at the specified path. If the file does not exist, the method does not throw an exception ...

Read More

How to add integer values to a C# list?

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

To add integer values to a List in C#, you can use several methods including Add(), AddRange(), and collection initializer syntax. The Add() method is the most common way to add individual values one at a time. Syntax Following is the syntax for declaring an integer list and adding values − List listName = new List(); listName.Add(value); To add multiple values at once using AddRange() − listName.AddRange(new int[] { value1, value2, value3 }); Using collection initializer syntax − List listName = new List { value1, value2, value3 }; ...

Read More
Showing 781–790 of 25,467 articles
« Prev 1 77 78 79 80 81 2547 Next »
Advertisements