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 George John
Page 5 of 79
C# Convert.ToInt32 Method
The Convert.ToInt32 method in C# is used to convert various data types to a 32-bit signed integer. It is commonly used to convert strings, floating-point numbers, and other numeric types to integers, providing a versatile approach to type conversion. Syntax Following are the most common syntax forms for Convert.ToInt32 − Convert.ToInt32(value); Convert.ToInt32(value, fromBase); Parameters value − The value to convert (string, double, decimal, bool, etc.) fromBase − Optional. The base of the number system (2, 8, 10, or 16) Return Value Returns a 32-bit signed integer equivalent to the ...
Read MoreSingly LinkedList Traversal using C#
A LinkedList in C# is a doubly-linked list that allows efficient insertion and removal of elements. Traversal refers to visiting each node in the LinkedList sequentially to access or process the data. The LinkedList class in C# provides various methods to traverse through its elements, with the most common approach being the foreach loop. Syntax Following is the syntax for declaring a LinkedList − var linkedList = new LinkedList(); Following is the syntax for traversing a LinkedList using foreach − foreach(var item in linkedList) { // Process each ...
Read MoreReplace a C# array with a new array of different size
To replace a C# array with a new array of different size, use the Array.Resize method. This method allows you to change the size of an existing array, either expanding or shrinking it while preserving existing elements. Syntax Following is the syntax for using Array.Resize − Array.Resize(ref array, newSize); Parameters array − The array to resize (passed by reference using ref) newSize − The new size of the array How It Works When you resize an array: If the new size is ...
Read MoreHow to find maximum between 2 numbers using C#?
Finding the maximum between two numbers in C# can be accomplished using several approaches. The most common methods include using conditional statements, the Math.Max() method, and the ternary operator. Using If-Else Statement The traditional approach uses an if-else statement to compare two numbers and determine which one is larger − using System; class Program { static void Main(string[] args) { int num1 = 50; int num2 = 90; ...
Read MoreWhat is the use of 'Using' statement in C#?
The using statement in C# is used for automatic resource management and memory cleanup. It ensures that resources are properly disposed of when they are no longer needed, even if an exception occurs. The using statement works with objects that implement the IDisposable interface. The main goal of the using statement is to manage resources and automatically release them when the code block completes execution. This is particularly useful for file operations, database connections, and other system resources that need explicit cleanup. Syntax Following is the syntax for the using statement − using (ResourceType resource ...
Read MoreUse ReaderWriter Lock in C#
The ReaderWriterLock class in C# provides synchronized access to a resource by allowing multiple threads to read simultaneously while ensuring exclusive access for writing operations. It offers better performance than Monitor for scenarios where reads are frequent and writes are infrequent. Note: ReaderWriterLock is obsolete since .NET 3.5. The recommended alternative is ReaderWriterLockSlim, which provides better performance and functionality. Syntax Following is the syntax for declaring a ReaderWriterLock − static ReaderWriterLock rwLock = new ReaderWriterLock(); Following is the syntax for acquiring and releasing locks − // Acquire reader lock rwLock.AcquireReaderLock(timeout); try ...
Read MoreC# program to remove the first occurrence of a node in a Linked List
The LinkedList class in C# provides an efficient way to store and manipulate collections of data. When you need to remove the first occurrence of a specific node from a LinkedList, you can use the Remove() method, which searches for the specified value and removes its first occurrence. Syntax The syntax for removing the first occurrence of a node from a LinkedList is − bool result = linkedList.Remove(value); Parameters value − The value to remove from the LinkedList. The method removes the first node that contains this value. Return Value The Remove()
Read MoreC# program to implement FizzBuzz
The FizzBuzz problem is a classic programming exercise that involves printing numbers from 1 to 100 with specific replacements. If a number is divisible by 3, print "Fizz". If divisible by 5, print "Buzz". If divisible by both 3 and 5, print "FizzBuzz". Otherwise, print the number itself. This problem tests your understanding of conditional statements, loops, and the modulo operator in C#. Syntax The modulo operator % is used to check divisibility − if (number % divisor == 0) { // number is divisible by divisor } The logical ...
Read MoreOverloaded method and ambiguity in C#
With method overloading, you can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. However, when using default parameters with overloaded methods, ambiguity can occur if the compiler cannot determine which method to call. Syntax Following is the syntax for method overloading − public void MethodName(int parameter1) { // Implementation 1 } public void MethodName(int parameter1, int parameter2) { // Implementation 2 ...
Read MoreImplicit conversion from Int32 to Decimal in C#
The int type represents a 32-bit signed integer (Int32) in C#. C# allows implicit conversion from int to decimal because this conversion is always safe and does not result in data loss. The decimal type has a much larger range and precision than int. Syntax The syntax for implicit conversion from Int32 to decimal is straightforward − int intValue = 123; decimal decimalValue = intValue; // implicit conversion No explicit casting is required because the conversion is safe and automatic. How Implicit Conversion Works When you assign an int value to ...
Read More