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 Chandu yadav
Page 5 of 81
What is the scope of a private member variable of a class in C#?
The scope of a private member variable in C# is limited to the class in which it is declared. Only methods and properties within the same class can directly access private members. This implements the principle of data encapsulation, which hides internal implementation details from external code. Syntax Following is the syntax for declaring private member variables − private dataType variableName; Private members can only be accessed by methods within the same class − class ClassName { private int value; public void ...
Read MoreTrigonometric Functions in C#
Trigonometric functions in C# are part of the Math class in the System namespace. These functions enable you to perform mathematical calculations involving angles, including basic trigonometric operations (Sin, Cos, Tan) and their inverse functions (Asin, Acos, Atan). All angle measurements in C# trigonometric functions are in radians, not degrees. To convert degrees to radians, multiply by π/180. Common Trigonometric Functions Function Description Return Type Math.Sin(double) Returns the sine of the specified angle double Math.Cos(double) Returns the cosine of the specified angle double Math.Tan(double) Returns the ...
Read MoreHow to find the size of a list in C#?
A List in C# is a dynamic collection that can grow or shrink in size. To determine the size of a list, you can use two different properties: Count (for the number of actual elements) and Capacity (for the total allocated space). Syntax To get the number of elements in a list − listName.Count To get the total capacity (allocated space) of a list − listName.Capacity Understanding Count vs Capacity Count vs Capacity Count Number of actual ...
Read MoreConvert.ToChar Method in C#
The Convert.ToChar() method in C# converts a specified value to its equivalent Unicode character representation. This method accepts various data types including integers, bytes, strings, and other numeric types, and returns a char value. Syntax Following are the common overloads of the Convert.ToChar() method − public static char ToChar(byte value) public static char ToChar(int value) public static char ToChar(string value) public static char ToChar(object value) Parameters value − The value to be converted to a Unicode character. This can be a numeric type, string, or object. Return Value ...
Read MoreHow to delete/remove an element from a C# array?
In C#, arrays have a fixed size once created, so you cannot truly delete an element. However, you can remove an element by shifting the remaining elements to fill the gap, or use collections like List for dynamic removal. Understanding Array Element Removal When removing an element from an array, the process involves shifting all elements after the target position one position to the left, effectively overwriting the element to be removed. Array Element Removal Process Original: 35 ...
Read MoreC# program to iterate over a string array with for loop
A string array in C# can be iterated using a for loop to access each element by its index. The loop runs from index 0 to the length of the array minus one, allowing you to process each string element sequentially. Syntax Following is the syntax for iterating over a string array with a for loop − for (int i = 0; i < arrayName.Length; i++) { // Access element: arrayName[i] } The Length property returns the total number of elements in the array, and the loop variable i serves ...
Read MoreHow to get the nth value of a Fibonacci series using recursion in C#?
The Fibonacci series is a sequence where each number is the sum of the two preceding numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21... In C#, we can use recursion to calculate the nth Fibonacci number by breaking the problem into smaller subproblems. Recursion works by having the method call itself with reduced parameters until it reaches a base case. For Fibonacci, the base cases are F(0) = 0 and F(1) = 1. Syntax Following is the syntax for a recursive Fibonacci method − public int Fibonacci(int n) { if ...
Read MoreC# Program to return a collection with repeated elements
To return a collection with repeated elements in C#, use the Enumerable.Repeat method from the System.Linq namespace. This method creates a sequence that contains one repeated value a specified number of times. Syntax Following is the syntax for Enumerable.Repeat method − public static IEnumerable Repeat(TResult element, int count) Parameters element − The value to be repeated in the result sequence. count − The number of times to repeat the value in the generated sequence. Return Value Returns an IEnumerable that contains a repeated value. ...
Read MoreC# program to separate joined strings in C#
In C#, you can join string arrays into a single string using string.Join() and then separate the joined string back into individual elements using the Split() method. This is useful when you need to manipulate strings by combining them temporarily and then extracting the original components. Syntax Following is the syntax for joining strings − string joinedString = string.Join(separator, stringArray); Following is the syntax for separating joined strings − string[] separatedArray = joinedString.Split(separator); Parameters separator − The character or string used to separate elements during joining and ...
Read MoreInteger literals vs Floating point literals in C#
In C#, literals are fixed values written directly in the source code. There are two main categories of numeric literals: integer literals for whole numbers and floating-point literals for decimal numbers. Understanding the difference between these literals is essential for proper variable declaration and avoiding compilation errors. Integer Literals An integer literal represents a whole number without a decimal point. Integer literals can be decimal (base 10) or hexadecimal (base 16). A prefix specifies the base: 0x or 0X for hexadecimal, with no prefix for decimal. Syntax decimal_literal // 10, 100, ...
Read More