
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2587 Articles for Csharp

1K+ Views
Multi-dimensional arrayMulti-dimensional arrays are also called rectangular array. You can define a 3-dimensional array of integer as −int [ , , ] val;Let us see how to define a two-dimensional array.int[,] val = new[3,3] Jagged arrayA Jagged array is an array of arrays. To access an element from it, just mention the index for that particular array.Here, we have a jagged array with 5 array of integers −int[][] a = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }};

493 Views
List collection is a generic class and can store any data types to create a list. To define a List −List l = new List();To set elements in a list, you need to use the Add method.l.Add("One"); l.Add("Two"); l.Add("Three");An array stores a fixed-size sequential collection of elements of the same type.To define Arrays −int[] arr = new int[5]; To initialize and set elements to Arrays −int[] arr = new int[5] {4, 8,5};

797 Views
To copy a C# list collection to an array, firstly set a list −List list1 = new List (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four");Now declare a string array and use the CopyTo() method to copy −string[] arr = new string[20]; list1.CopyTo(arr);Let us see the complete code to copy a list into a one – dimensional array.Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List list1 = new List (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four"); ... Read More

3K+ Views
The default access for a class member in C# is private.Member variables i.e. class members are the attributes of an object (from design perspective) and they are kept private to implement encapsulation. These variables can only be accessed using the public member functions.Exampleusing System; namespace RectangleApplication { class Rectangle { //member variables private double length; private double width; public void Acceptdetails() { length = 10; width = 14; } public ... Read More

2K+ Views
To set final for a local variable, use the read-only keyword in C#, since the implementation of the final keyword is not possible.The readonly would allow the variables to be assigned a value only once. A field marked "read-only", can only be set once during the construction of an object. It cannot be changed.Let us see an example. Below, we have set the empCount field as read-only, which once assigned cannot be changed.Exampleclass Department { readonly int empCount; Employee(int empCount) { this. empCount = empCount; } void ChangeCount() { //empCount = 150; // Compile error } }

186 Views
The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).The following are the method of the index-based BitArray collection −Sr.No.Method & Description1public BitArray And(BitArray value);Performs the bitwise AND operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.2public bool Get(int index);Gets the value of the bit at a specific position in the BitArray.3public BitArray Not();Inverts all the bit values in the current BitArray, so that elements set to true are changed to ... Read More

464 Views
ArrayList class represents an ordered collection of an object that can be indexed individually. It is an alternative to an array.The following table lists some of the commonly used properties of the ArrayList class −Sr.NoProperty & Description1CapacityGets or sets the number of elements that the ArrayList can contain.2CountGets the number of elements actually contained in the ArrayList.3IsFixedSizeGets a value indicating whether the ArrayList has a fixed size.4IsReadOnlyGets a value indicating whether the ArrayList is read-only.5ItemGets or sets the element at the specified index.The following is an example showing how to work with ArrayList in C# and finding the capacity. The ... Read More

923 Views
The following is the difference between implicit and explicit type conversion −Implicit Type ConversionThese conversions are performed by C# in a type-safe manner.To understand the concept, let us implicitly convert int to long.int val1 = 11000; int val2 = 35600; long sum; sum = val1 + val2;Above, we have two integer variable and when we sum it in a long variable, it won’t show an error. Since the compiler does the implicit conversion on its own.Let us print the values now.Exampleusing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) ... Read More

2K+ Views
Internal Access SpecifierInternal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly.Any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.The following is an example −Exampleusing System; namespace RectangleApplication { class Rectangle { //member variables internal double length; internal double width; double GetArea() { return length * width; } ... Read More

784 Views
Type conversion is converting one type of data to another type. Explicit conversions are done explicitly by users using the pre-defined functions and require a cast operator.Let us see an example to cast double to int −Exampleusing System; namespace Demo { class Program { static void Main(string[] args) { double a = 4563.56; int x; x = (int)a; Console.WriteLine(x); Console.ReadKey(); } } }To cast double to int, we perfomed explicit type casting −x = (int)a;