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 81 of 2547
How to create 5-Tuple or quintuple in C#?
A 5-tuple or quintuple in C# is represented by the Tuple class, which is a data structure that holds exactly five elements of potentially different types. Each element can be accessed through its corresponding Item property. Syntax Following is the syntax for creating a 5-tuple using the constructor − Tuple tuple = new Tuple(item1, item2, item3, item4, item5); You can also use the Tuple.Create() method for shorter syntax − var tuple = Tuple.Create(item1, item2, item3, item4, item5); Properties A 5-tuple has five read-only properties to access its elements − ...
Read MoreWhat are pointers in C#?
A pointer is a variable that stores the memory address of another variable. Unlike reference types, pointers provide direct access to memory locations, making them powerful but potentially unsafe. In C#, pointers can only be used within unsafe code blocks or methods. This restriction exists because pointers bypass .NET's garbage collection and type safety mechanisms. Syntax Following is the syntax for declaring a pointer − type *pointerName; Following is the syntax for getting the address of a variable − type *pointer = &variable; Following is the syntax for dereferencing ...
Read MoreWhat is the difference between public, static and void keywords in C#?
The public, static, and void keywords in C# have specific meanings and are commonly seen together in the Main method of any C# program. Understanding these keywords is essential for C# programming as they control access, memory allocation, and return behavior of methods. The Main method serves as the entry point for all C# programs, defining what a class does when executed. Syntax Following is the typical syntax of the Main method showing all three keywords − public static void Main(string[] args) { // program execution starts here } ...
Read MoreCharacter constants vs String literals in C#
In C#, both character constants and string literals are used to represent text data, but they serve different purposes and have distinct syntax rules. Character constants represent single characters, while string literals represent sequences of characters (text). Character Constants Character constants are enclosed in single quotes and represent a single character. They are stored in variables of type char. Syntax char variableName = 'character'; Character constants can be − Plain characters − 'x', 'A', '5' Escape sequences − '', '\t', '' Unicode characters − '\u0041' (represents 'A') Example ...
Read MoreMath.BigMul() Method in C#
The Math.BigMul() method in C# is used to calculate the full product of two 32-bit integers. This method is particularly useful when multiplying large integers that might produce a result exceeding the range of a 32-bit integer, as it returns a 64-bit long value to accommodate the full product. Syntax Following is the syntax − public static long BigMul(int val1, int val2); Parameters val1: The first 32-bit integer to multiply val2: The second 32-bit integer to multiply Return Value Returns a long (64-bit integer) containing ...
Read MoreHow to create 6-Tuple in C#?
A 6-tuple in C# is represented by the Tuple class, which is a data structure that holds exactly six elements of potentially different types. Tuples are useful for grouping related data together without creating a custom class or struct. The 6-tuple provides six properties to access its elements: Item1 through Item6, each corresponding to the respective component in the tuple. Syntax Following is the syntax for creating a 6-tuple − Tuple tupleName = new Tuple(value1, value2, value3, value4, value5, value6); You can also use the Tuple.Create() method for shorter syntax − ...
Read MoreHow to pass pointers as parameters to methods in C#?
To pass pointers as parameters to methods in C#, you need to use unsafe code and pointer syntax. Pointers allow direct memory manipulation and can be passed to methods for operations like swapping values or modifying data directly in memory. C# requires the unsafe keyword when working with pointers, and your project must be configured to allow unsafe code compilation. Syntax Following is the syntax for declaring a method that accepts pointer parameters − public unsafe void MethodName(int* pointer1, int* pointer2) { // pointer operations } Following is the ...
Read MoreHow to add read-only property in C#?
A read-only property in C# is a property that can only be set during object initialization and cannot be modified afterward. There are several ways to create read-only properties, including using the readonly keyword with fields, properties with only getters, and init-only properties (available in C# 9.0+). Syntax Following is the syntax for a read-only field − readonly dataType fieldName; Following is the syntax for a read-only property with only a getter − public dataType PropertyName { get; } Following is the syntax for an init-only property (C# 9.0+) − ...
Read MoreWhat is the equivalent of a VB module in C#?
In VB.NET, a module is used to store loose code and variables that are accessible from anywhere in the application without needing to instantiate an object. Variables in a module maintain their state throughout the application lifetime. The C# equivalent of a VB.NET module is a static class. Static classes provide the same functionality − global accessibility without instantiation and persistent state through static members. Syntax Following is the syntax for creating a static class in C# − public static class ClassName { public static void MethodName() { ...
Read MoreWhat is the IsReadOnly property of SortedList class in C#?
The IsReadOnly property of the SortedList class in C# returns a boolean value indicating whether the collection is read-only. A read-only collection cannot be modified after creation − you cannot add, remove, or update elements. For standard SortedList instances created using the default constructor, this property always returns false, meaning the collection is modifiable. Syntax Following is the syntax for using the IsReadOnly property − bool isReadOnly = sortedList.IsReadOnly; Return Value The IsReadOnly property returns − true − if the SortedList is read-only false − if the SortedList can be ...
Read More