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 822 of 2547
What is a non-static class in C#?
A non-static class in C# is a regular class that can be instantiated using the new keyword. Unlike static classes, non-static classes allow you to create multiple objects (instances) and can contain both instance members and static members. Non-static classes are the default type of class in C# and form the foundation of object-oriented programming, enabling encapsulation, inheritance, and polymorphism. Syntax Following is the syntax for declaring a non-static class − public class ClassName { // instance fields // static fields // instance ...
Read MoreImplicit conversion from 16-bit unsigned integer (ushort) to Decimal in C#
ushort represents a 16-bit unsigned integer in C# with a range from 0 to 65, 535. C# allows implicit conversion from ushort to decimal because this conversion is always safe and does not result in data loss. The decimal type can accommodate the entire range of ushort values without precision loss, making implicit conversion possible. Syntax Following is the syntax for implicit conversion from ushort to decimal − ushort ushortValue = value; decimal decimalValue = ushortValue; // implicit conversion How It Works The conversion happens automatically without requiring explicit casting or ...
Read MoreHow to use the Main() method in C#?
The Main() method in C# is the entry point of any C# application. It is a static method that runs when the program starts, without requiring an instance of the class to be created. The Main() method defines what the class does when executed and can instantiate other objects and variables. Syntax Following are the valid signatures for the Main() method − static void Main() static void Main(string[] args) static int Main() static int Main(string[] args) Parameters The Main() method signature includes the following components − static − The method ...
Read MoreWhat are Left Shift and Right Shift Operators (>> and <<) in C#?
The left shift () operators in C# are bitwise operators that shift the bits of a number left or right by a specified number of positions. These operators are commonly used for efficient multiplication and division by powers of 2, as well as for low-level bit manipulation. Syntax Following is the syntax for the left shift operator − result = operand > numberOfPositions; How Left Shift Works The left shift operator (> 3; /* Right shift by 3: 60 / 8 = 7 */ Console.WriteLine("60 >> 3 ...
Read MoreFull Date Long Time ("F") Format Specifier in C#
The Full Date Long Time ("F") format specifier in C# displays a complete date and time representation in a long format. This format specifier uses the current culture's DateTimeFormatInfo.FullDateTimePattern property to determine the exact format string. The "F" specifier provides the most comprehensive date and time display, showing the full day name, complete date, and precise time including seconds. Syntax Following is the syntax for using the "F" format specifier − DateTime.ToString("F") DateTime.ToString("F", CultureInfo) The default custom format string for "F" is − dddd, dd MMMM yyyy HH:mm:ss Using ...
Read MoreHow to use the return statement in C#?
The return statement in C# is used to exit a method and optionally return a value to the caller. When a method contains a return statement, the program control immediately transfers back to the calling method along with the specified return value. Syntax Following is the syntax for using the return statement − return; // For void methods (no value returned) return expression; // For methods that return a value Using Return Statement with Value Types When a method has a return type other than void, it must return a ...
Read MoreMath.Sin() Method in C#
The Math.Sin() method in C# is used to return the sine of a specified angle. The method accepts an angle in radians and returns a double value representing the sine of that angle. Syntax Following is the syntax for the Math.Sin() method − public static double Sin(double val); Parameters val − A double value representing an angle in radians. Return Value The method returns a double value representing the sine of the specified angle. The return value ranges from -1 to 1. For special cases − ...
Read MoreC# program to check if a Substring is present in a Given String
The Contains() method in C# is used to check if a substring is present within a given string. It returns a boolean value − true if the substring is found, and false otherwise. Syntax Following is the syntax for the Contains() method − bool result = string.Contains(substring); Parameters substring − The string to search for within the main string. Return Value The Contains()
Read MoreHow is an array initialized in C#?
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. In C#, arrays must be properly initialized before you can use them to store and access data. Array Declaration vs Initialization Firstly, declare an array − int[] rank; But declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance ...
Read MoreWhat are virtual functions in C#?
The virtual keyword in C# allows a method, property, indexer, or event to be overridden in derived classes. Virtual functions enable runtime polymorphism, where the actual method called is determined at runtime based on the object's type, not the reference type. When you define a virtual function in a base class, derived classes can provide their own implementations using the override keyword. This allows different derived classes to implement the same method differently while maintaining a common interface. Syntax Following is the syntax for declaring a virtual method − public virtual returnType MethodName() { ...
Read More