Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 79 of 2547
C# Object Creation of Inherited Class
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 MoreDictionary.Item[] Property in C#
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 MoreHow to calculate Power of a number using recursion in C#?
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 MoreWhat is abstraction in C#?
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 MoreC# Program to make a copy of an existing file
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 MoreC# Nullable Datetime
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 MoreDictionary.Keys Property in C#
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 MoreCopyOnWriteArrayList version in C#
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 MoreDelete a file in C#
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 MoreHow to add integer values to a C# list?
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