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
Articles by karthikeya Boyini
Page 12 of 143
Static vs. Non-Static method in C#
In C#, methods can be declared as either static or non-static (instance methods). Static methods belong to the class itself and can be called without creating an instance of the class, while non-static methods belong to specific instances of the class. Static methods can only access static variables and other static members directly. They exist even before any object of the class is created and are shared across all instances of the class. Syntax Following is the syntax for declaring a static method − public static returnType MethodName() { // method ...
Read MoreBasic calculator program using C#
A calculator program in C# can be built using either Windows Forms or Console applications. This tutorial demonstrates how to create a basic calculator that performs fundamental arithmetic operations like addition, subtraction, multiplication, and division. We'll create a complete console-based calculator that takes user input and performs calculations, making it easy to understand the core logic before moving to GUI implementations. Console-Based Calculator Basic Calculator with Menu using System; class Calculator { public static void Main(string[] args) { double num1, num2, result; ...
Read MoreC# Linq Intersect Method
The Intersect() method in C# LINQ is used to find common elements between two collections. It returns a new sequence containing elements that exist in both the source collection and the specified collection, with duplicates automatically removed. Syntax Following is the syntax for the Intersect() method − public static IEnumerable Intersect( this IEnumerable first, IEnumerable second ) With a custom equality comparer − public static IEnumerable Intersect( this IEnumerable first, IEnumerable second, ...
Read MoreWhat is the Capacity property of an ArrayList class in C#?
The Capacity property in the ArrayList class gets or sets the number of elements that the ArrayList can contain. This property represents the internal array size, which is automatically managed by the ArrayList to optimize performance. The capacity is always greater than or equal to the count of elements. When elements are added and the capacity is exceeded, the ArrayList automatically doubles its capacity to accommodate more elements. Syntax Following is the syntax for accessing the Capacity property − arrayListName.Capacity You can also set the capacity explicitly − arrayListName.Capacity = newCapacityValue; ...
Read MoreRetrieving Elements from Collection in C#
Collections in C# provide various ways to retrieve elements. The List collection is one of the most commonly used collections that allows you to access elements by index, retrieve specific elements, or iterate through all elements. Syntax Following is the syntax for accessing elements by index − ElementType element = list[index]; Following is the syntax for using foreach to iterate through all elements − foreach (ElementType item in list) { // process item } Using Index-Based Access You can retrieve elements from a List collection using ...
Read MoreBitwise right shift operators in C#
The bitwise right shift operator (>>) in C# moves the bits of the left operand to the right by the number of positions specified by the right operand. This operation effectively divides the number by powers of 2. Syntax Following is the syntax for the bitwise right shift operator − result = operand >> numberOfPositions; How It Works When you right shift a binary number, each bit moves to the right by the specified number of positions. Vacant positions on the left are filled with zeros for positive numbers and ones for negative ...
Read MoreWhat is the Count property of BitArray class in C#?
The Count property of the BitArray class in C# returns the total number of elements (bits) in the BitArray. This is a read-only property that gives you the size of the BitArray, which is determined when the BitArray is created. Syntax Following is the syntax for accessing the Count property − int count = bitArray.Count; Return Value The Count property returns an int value representing the number of bits in the BitArray. Using Count Property with BitArray Let us first create a BitArray and then use the Count property to get ...
Read MoreVirtual vs Sealed vs New vs Abstract in C#
In C#, virtual, sealed, new, and abstract are important keywords that control method inheritance and overriding behavior. Understanding these modifiers is crucial for implementing proper object-oriented design patterns and controlling how classes interact through inheritance. Virtual The virtual keyword allows a method in a base class to be overridden in derived classes. When a method is declared as virtual, derived classes can provide their own implementation using the override keyword. Syntax public virtual ReturnType MethodName() { // base implementation } Example using System; class Animal { ...
Read MoreC# Queryable Max Method
The Queryable.Max() method in C# returns the maximum value from a sequence of numeric values. It operates on IQueryable collections and provides query optimization for data sources like Entity Framework. Syntax Following is the syntax for the Max() method − public static TSource Max(this IQueryable source) public static TResult Max(this IQueryable source, Expression selector) Parameters source − An IQueryable sequence of values to determine the maximum value of. selector − A transform function to apply to each element (optional overload). Return Value Returns the maximum ...
Read MoreHow to use the GetType method of array class in C#?
The GetType() method in C# is inherited from the Object class and returns the exact runtime type of the current instance. When used with arrays, it provides information about the array's type, including its element type and dimensions. Syntax Following is the syntax for using the GetType() method − Type type = arrayInstance.GetType(); Return Value The method returns a Type object that represents the exact runtime type of the current instance. Using GetType() with Arrays When applied to arrays, GetType() returns the array type, which includes information about the element type ...
Read More