Skip to main content

C# Tutorial, Arrays

Hi, Welcome to all. My name is Abdul Yesdani. Today we are going to learn about arrays in C#.

In our previous postings we have worked with variables. One variable can store only one value. If we want to store multiple values of same type, array variable is there to do that job.

What is an array?

An array variables is capable of storing multiple values of same type.  

Syntax:  datatype[ ] arrayName = new datatype[size];

Example: int [ ] myNumbers = new int [ 5];

 The above array variable  myNumbers is capable of storing 5 integer values.

In the memory it will allocate 5 slots to store 5 values, index starting from 0 to 4. Array indexing will always start with 0 and end with size -1.

Types of Arrays in C# :

There are 3 types of array in C#.  Single dimensional array, multi dimensional array and jagged array.

Single dimension array represent a single column or row of values. The above example is for the same.


Multi dimension array represent 2 dimension or 3 dimension or 'n' dimension of arrays. You can assume it as an array of arrays.

example: int [ , ] twoDarray = new int[3,4]; We can print 3 rows with 4 columns matrix.




Jagged array represent 'n' number of arrays with each one having varied length.

example: int [ ][ ]  jaggedarray = new int[3][ ];

               jaggedarray[0]= new int[3]{34,45,56};

               jaggedarray[1] = new int[2 ] {33,99};

               jaggedarray[2]= new int[5 ] {10,20,30,40,50};



watch video








 

Comments

Post a Comment

Popular posts from this blog

Building a Responsive Weather App with React

 Fetching and Displaying Weather Data      By - ABDUL YESDANI Objective:  This document will help you prepare for the workshop on building a responsive weather app using React. You will learn the basics of React, how to use APIs, and how to work with data fetched from an API. By the end of the workshop, you’ll build a simple weather app that fetches real-time weather data.  1. What is React? React is a JavaScript library used to build user interfaces, especially for single-page applications. It lets you create components, which are reusable, isolated pieces of code that define a part of your user interface. Key Terms Component : Think of components as building blocks for your app. Each part of your app’s UI can be a component, like a button, form, or navigation bar. JSX : A syntax extension for JavaScript, which looks a lot like HTML. JSX is used to describe what the UI should look like. State : Data that controls what gets rendered on the screen. State can change over time, like inpu

node.js tutorial

node.js is a open source server environment. Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js is free,it is cross platform means runs on various platforms (Windows, Linux, Unix, Mac). Node.js uses JavaScript on the server.

.Net Presentation

.NET is a free, cross-platform, open source developer platform for building many different types of applications. With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, and IoT. You can write .NET apps in C#, F#, or Visual Basic. C# is a simple, modern, object-oriented, and type-safe programming language. F# is a programming language that makes it easy to write succinct, robust, and performant code. Visual Basic is an approachable language with a simple syntax for building type-safe, object-oriented apps. You can write .NET apps in C#, F#, or Visual Basic. C# is a simple, modern, object-oriented, and type-safe programming language. F# is a programming language that makes it easy to write succinct, robust, and performant code. Visual Basic is an approachable language with a simple syntax for building type-safe, object-oriented apps.