Main menu

Pages

Arrays in c# Programming - Learn c sharp

Arrays in c# Programming - Learn c sharpArray: It is a set of numbers arranged in the form of rows and columns, and these numbers are usually real or complex numbers. Arrays are important terms in the field of programming languages that programmers cannot dispense with. Arrays are one of the good tools that can be used in the field of data storage, which facilitates the process of accessing and returning data, as each variable within the array has its own number called (index) the variable is accessed through this number.


Arrays in c# - Learn c sharp


Arrays definition in C#


The C Sharp programming language allows us to manipulate arrays and define them as follows:


  • Type [] name = new Type [Size];


Here the type of the matrix is mentioned, then we write the matrix symbol before the name of the matrix, followed by the equal sign, and we write the reserved word (new) then the same type that we wrote at the beginning of the sentence and then we mention the size. This example shows how to define the matrix and determine its size:


  • int []x = new int [3];


When we use the reserved word (new) to define arrays, we are able to treat them as pointers; In order to get out of the ordinary because it is (Dynamic) instead of (Static), and with this step, the C Sharp language has become similar to the Java language, and in the previous sentence we reserved a place for it in memory and did not give it initial values, so you can give it initial values in two different ways:


  • While holding the array, it can be given initial values, as in the following example:


  • int []x = new int [5]{4,3,7,22,8}


Here we assign values to the array immediately when it is defined.


  • It is also possible to give values to the array after its definition as well as in the following example:


  • int []x = new int[3] ;
  • x[0] = 21;
  • x[1] = 63;
  • x[2] = 7;


Decrement and Increment operators:


The CSharp programming language allows you to increment variables of the correct type in several ways, the most famous of which is the traditional method of writing the variable on one side and incrementing it on the other, as follows:


  • Var = Var (operation) value ; 
  • i+= 4; 
  • Here we increment the variable by 4.


Now we will talk about increment operators with a value of only one. Here you can increment a variable with a value of only 1 with the following expression:


  • Var++;
  • ++Var;


Also, you can use the decrement factor using the following formula:


  • Var- ;
  • -Var;