Posts

Introduction

 What is C#? C# is a server side programing language and it is developed by  Anders Hejlsberg C# is mainly used to develop different kinds of applications mainly 3 types Windows applications web applications

TypesOfCollections

 1.Generic collections/System.Collections.Generic 2.Non-Generic collections/System.Collections  3.Concurrent collections/System.Collections.Concurrent Generic collections/System.Collections.Generic: List Stack Queue LinkedList HashSet SortedSet Dictionary SortedDictionary SortedList Non-Generic collections/System.Collections: ArrayList Stack Queue Hashtable Concurrent collections/System.Collections.Concurrent: BlockingCollection ConcurrentBag ConcurrentStack ConcurrentQueue ConcurrentDictionary Partitioner Partitioner OrderablePartitioner

CallByValue&Reference

 1. Call by Value : Call by value is a method of passing arguments to a function where the actual value of the argument is passed to the function. In call by value, the function receives a copy of the argument's value, not the original variable. Changes made to the parameter inside the function do not affect the original value outside the function. Primitive data types like integers, floats, and characters are typically passed by value. Example in C#: void Increment(int x) { x++; // Increment the copy of x } int num = 10; Increment(num); // Call by value Console.WriteLine(num); // Output: 10 (original value unchanged) 2.Call by Reference : Call by reference is a method of passing arguments to a function where the reference (memory address) of the variable is passed to the function. In call by reference, the function receives a reference to the original variable, allowing it to modify the original value. Changes made to the parameter inside the function affect the original valu...

Types of Memories

  In C#, when we talk about "memory," we usually refer to the types of data storage or memory management available within the .NET runtime environment. Here are some common types of memory in C#: Stack Memory : Stack memory is used to store value types and references to objects. It operates in a last-in, first-out (LIFO) manner, and memory allocation and deallocation are handled automatically by the runtime. Local variables, method parameters, and return addresses are typically stored on the stack. Heap Memory : Heap memory is used to store objects and reference types. Memory allocation for objects on the heap is managed by the garbage collector, which automatically frees up memory that is no longer in use. Objects on the heap can be accessed through references stored on the stack or in other objects. Garbage-Collected Memory : In C#, memory management is handled by a garbage collector, which automatically deallocates memory that is no longer needed by the program. The garbag...

Collections

  Arrays: Fixed-size collections of elements of the same type. ArrayList:Any datatype can be inserted List<T>: Dynamic arrays that automatically resize as needed. Dictionary<TKey, TValue>: Collection of key-value pairs. HashSet<T>: Collection of unique elements. Queue<T>: First-in-first-out (FIFO) collection. Stack<T>: Last-in-first-out (LIFO) collection. LinkedList<T>: Doubly linked list. SortedDictionary<TKey, TValue>: Sorted collection of key-value pairs. SortedSet<T>: Sorted collection of unique elements. Hashtable: Non-generic collection of key-value pairs . SortedDictionary<TKey, TValue>: Sorted collection of key-value pairs. SortedSet<T>: Sorted collection of unique elements. BitArray: Collection of bits that can be individually set or cleared. ConcurrentBag<T>: Thread-safe collection for unordered bags of objects. ConcurrentDictionary<TKey, TValue>: Thread-safe collection of key-value pairs. ConcurrentQ...

Conditional statements:

 In C#, conditional statements are used to control the flow of execution based on certain conditions. Types: 1.if 2.if-else 3.else if 4.switch 1.if statement: The if statement is used to execute a block of code if a specified condition is true. *Single Statement if (condition) {     // Code to be executed if the condition is true } 2.if-else statement: The if-else statement allows you to execute one block of code if the condition is true and another block if the condition is false. *Two Statements if (condition) {     // Code to be executed if the condition is true } else {     // Code to be executed if the condition is false } 3.else if statement: The else if statement is used when you have multiple conditions to check. *Multiple Statements if (condition1) {     // Code to be executed if condition1 is true } else if (condition2) {     // Code to be executed if condition2 is true } else {     // Code to be executed if none...

Constructor

 In C#, a constructor is a special method in a class that is automatically called when an object of that class is created. It can be used to set initial values for fields. Types of Constructor 1.Default Constructor 2.Parameterized Constructor 3.Copy Constructor 4.Private Constructor 5.Static Constructor Definetions: 1.Default Constructor: If a class doesn't have any explicitly defined constructors, C# provides a default constructor with no parameters. 2.Parameterized Constructor: A constructor having at least one parameter is called as parameterized constructor. It can initialize each instance of the class to different values. 3.Copy Constructor: This constructor creates an object by copying variables from another object. Its main use is to initialize a new instance to the values of an existing instance.  4.Private Constructor: If a constructor is created with private specifier is known as Private Constructor. It is not possible for other classes to derive from this class and ...