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 859 of 2547
C# program to find additional values in two lists
Finding additional values between two lists is a common requirement in C# programming. This involves identifying elements that exist in one list but not in another. The Except() method from LINQ provides an efficient way to find the difference between two collections. Syntax The Except() method returns elements from the first sequence that are not present in the second sequence − IEnumerable result = list1.Except(list2); To find differences in both directions, you can use − var onlyInList1 = list1.Except(list2); var onlyInList2 = list2.Except(list1); Using Except() to Find Additional Values ...
Read MoreFibonacci Series in C#
The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding numbers. The series typically starts with 0 and 1, producing the sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. In C#, there are multiple ways to generate the Fibonacci series, including iterative and recursive approaches. Fibonacci Series Pattern 0 1 1 2 3 ...
Read MoreC# object serialization
Object serialization in C# is the process of converting an object into a stream of bytes for storage or transmission. The serialized data can be saved to files, databases, or sent over a network, and later deserialized back into objects. C# provides several approaches for serialization, including binary serialization, XML serialization, and JSON serialization. Binary serialization preserves the complete object state and type information. Syntax For binary serialization using BinaryFormatter − [Serializable] public class ClassName { // class members } BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, objectInstance); For deserialization ...
Read MoreHow to perform Division of Exponents of Same Base using C#?
When dividing exponents with the same base, we use the mathematical rule: a^m ÷ a^n = a^(m-n). This means we subtract the exponent in the denominator from the exponent in the numerator while keeping the base unchanged. In C#, we can implement this rule by subtracting the exponents and then using Math.Pow() to calculate the final result. Mathematical Rule The division rule for exponents with the same base is − a^m ÷ a^n = a^(m-n) For example: 10^10 ÷ 10^8 = 10^(10-8) = 10^2 = 100 Division of ...
Read MoreLocal Inner Class in C#
A nested class in C# is a class declared inside another enclosing class. The nested class is a member of its outer class and can access the outer class's private members, while the outer class cannot directly access the nested class's members without creating an instance. Nested classes provide better organization and encapsulation by grouping related functionality together. They are particularly useful when a class is only meaningful within the context of another class. Syntax Following is the syntax for declaring a nested class − class OuterClass { // outer class ...
Read MoreHow to iterate two Lists or Arrays with one foreach statement in C#?
When working with multiple collections in C#, you often need to iterate through them simultaneously. The Zip() method from LINQ provides an elegant solution to combine two arrays or lists and iterate them with a single foreach statement. Syntax Following is the syntax for using the Zip() method to combine two collections − var result = collection1.Zip(collection2, (item1, item2) => new { Prop1 = item1, Prop2 = item2 }); The lambda expression defines how to combine elements from both collections into a new anonymous object. Using Zip() with Arrays The Zip() method ...
Read MoreWhat is the use of 'new' keyword in C#?
The new keyword in C# serves multiple important purposes. It is primarily used to create new instances of classes, allocate memory for arrays, and hide inherited members from base classes. Syntax Following is the syntax for creating object instances using new − ClassName objectName = new ClassName(); Following is the syntax for creating arrays using new − dataType[] arrayName = new dataType[size]; Following is the syntax for hiding base class members using new − public new void MethodName() { // hides the base class method ...
Read MoreHow to pop the first element from a C# List?
To pop the first element from a C# List, you can use the RemoveAt() method with index 0. This method removes the element at the specified position and shifts all subsequent elements one position to the left. Unlike traditional stack pop operations that return the removed element, RemoveAt() only removes the element. If you need both removal and retrieval, you must first get the element before removing it. Syntax Following is the syntax for removing the first element − list.RemoveAt(0); Following is the syntax for popping (retrieving and removing) the first element − ...
Read MoreC# program to find the length of the Longest Consecutive 1's in Binary Representation of a given integer
Finding the longest consecutive 1's in the binary representation of a number is a common bit manipulation problem. The key is to use the bitwise AND operation combined with left shift to eliminate consecutive 1's one group at a time. Syntax The core operation uses bitwise AND with left shift − i = (i & (i
Read MoreC# Program to get the type of the specified Enumeration
Use the GetType() method to get the type of the specified enumeration in C#. This method returns a Type object that represents the actual enumeration type, which is useful for reflection, debugging, and type checking operations. When working with enumeration values, you can retrieve both the enumeration type and its underlying type using built-in methods provided by the Enum class and Type class. Syntax Following is the syntax for getting the type of an enumeration − Type enumType = enumValue.GetType(); To get the underlying type of an enumeration − Type underlyingType ...
Read More