Hot File

Build Jagged Arrays In C#

View: 287    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: C / C++ / MFC   Fields: Other

9 point/1 review File has been tested

Jagged Arrays In C# are special types of two-dimensional arrays also called nested arrays.

Introduction

Jagged Arrays In C# are special types of two-dimensional arrays also called nested arrays.

A jagged array is an array of arrays in which the length of each array can be different from other.

Elements of a jagged array are other arrays with its own length or sizes and dimensions.

Jagged array can be with multiple dimensions such as 2D, 3D etc.

General Syntax:

type [ ] [ ] array-name = new type[size] [ ];

Example – 1, Jagged Array using foreach loop:

using System;
namespace csharpBasic
{
    class Program
    {
        static void Main(string[] args)
        {
 
   // A string type Jagged Array declaration with size three.
            string[][] programingLanguages = new string[3][];
 
   // Statements assign each new arrays with its own sizes in each jagged array’s index which is from 0 to 2.
            programingLanguages[0] = new string[3];
            programingLanguages[1] = new string[2];
            programingLanguages[2] = new string[2];
 
   // Statements assign different elements or values in each inner array’ index.
            programingLanguages[0][0] = "C#";
            programingLanguages[0][1] = "Asp.net";
            programingLanguages[0][2] = "Css3";
 
            programingLanguages[1][0] = "Javascript";
            programingLanguages[1][1] = "Php";
 
            programingLanguages[2][0] = "Jquery";
            programingLanguages[2][1] = "Html5";
 
    // foreach loop iterates/extracts each inner or nested array from jagged array.
            foreach (string[] getInnerArray in programingLanguages)
 
    // foreach loop iterates/extracts each elements from (getInnerArray).
                foreach (string getInnerArrayElement in getInnerArray)
                    Console.WriteLine(getInnerArrayElement);
 
            Console.ReadKey();
        }
/*
        The Output will be:
         
        C#
        Asp.net
        Css3
        Javascript
        Php
        Jquery
        Html5
       */
    }
}

Example – 2, Jagged Array using nested for loop:

using System;
namespace csharpBasic
{
    class Program
    {
        static void Main(string[] args)
        {
            // A string type Jagged Array declaration and initialization once.
            string[][] programingLanguages = { 
                      new[] { "C#", "Asp.net", "Css3" }, 
                      new[] { "Javascript", "Php" }, 
                      new[] { "Jquery", "Html5" } 
            };
 
            // Outer loop iterates each jagged array’s index.
            for (int jaggedArrayIndex = 0; jaggedArrayIndex < 3; jaggedArrayIndex++)
 
                // Inner loop iterates each inner/nested array’s index.
                for (int innerArrayIndex = 0; innerArrayIndex < programingLanguages[jaggedArrayIndex].Length; innerArrayIndex++)
                    Console.WriteLine(programingLanguages[jaggedArrayIndex][innerArrayIndex]);
 
            Console.ReadKey();
        }
        /*
        The Output will be:
         
        C#
        Asp.net
        Css3
        Javascript
        Php
        Jquery
        Html5
       */
    }
}

Build Jagged Arrays In C#

Build Jagged Arrays In C# Posted on 07-09-2016  Jagged Arrays In C# are special types of two-dimensional arrays also called nested arrays. 9/10 287

Comment:

To comment you must be logged in members.

Files with category

  • How to Swap Two Numbers using Call by Reference in C

    View: 404    Download: 0   Comment: 0   Author: none  

    How to Swap Two Numbers using Call by Reference in C

    Category: C / C++ / MFC
    Fields: Other

    0/0 review
    How to swap two numbers using call by reference in C , C++. In the interviews interviewer generally asked the difference between call by reference and call by value

  • How to Print Fibonacci Series using Recursion in C, C++

    View: 411    Download: 0   Comment: 0   Author: none  

    How to Print Fibonacci Series using Recursion in C, C++

    Category: C / C++ / MFC
    Fields: Other

    4.5/1 review
    Write a program to print Fibonacci Series using recursion. Fibonacci series is a very important program in terms of interviews. To make this program little tough interviewer ask to write a fibonacci series code using recursion.

  • How to Implicitly Typed Arrays In C#

    View: 452    Download: 0   Comment: 0   Author: none  

    How to Implicitly Typed Arrays In C#

    Category: C / C++ / MFC
    Fields: Other

    0/1 review
    When we initialize these type of arrays with any data type, the compiler convert these arrays into that data type at compile time.

  • How to C# Static vs Instance Methods As Event Handlers

    View: 308    Download: 0   Comment: 0   Author: none  

    How to C# Static vs Instance Methods As Event Handlers

    Category: C / C++ / MFC
    Fields: Other

    0/0 review
    Both static and instance methods can be used as event handlers in C#

  • Build Pass By Reference To Method In C#

    View: 465    Download: 0   Comment: 0   Author: none  

    Build Pass By Reference To Method In C#

    Category: C / C++ / MFC
    Fields: Other

    0/3 review
    Like value types such as int, double, char etc. We can also pass a reference variable to the method in C# as its parameter which allows us to pass an object to the method and it is called pass by reference to method in C#.

  • How to C# Continue Statement

    View: 294    Download: 0   Comment: 0   Author: none  

    How to C# Continue Statement

    Category: C / C++ / MFC
    Fields: Other

    0/2 review
    continue statement skips or exits the current execution of a loop by given condition and keep execution continue for its next iteration unlike break statement it does not exit or terminate from loops, it terminates only its current execution

  • How to Single Dimensional Arrays In C#

    View: 238    Download: 0   Comment: 0   Author: none  

    How to Single Dimensional Arrays In C#

    Category: C / C++ / MFC
    Fields: Other

    0/1 review
    Single Dimensional Arrays in C# store each individual element at their single dimension, position or a specific location, that location is called an array index. Each index describes the position of each element within an array. Each element in an...

  • Build C# Multilevel Inheritance

    View: 259    Download: 0   Comment: 0   Author: none  

    Build C# Multilevel Inheritance

    Category: C / C++ / MFC
    Fields: Other

    2.5/2 review
    C# supports multilevel inheritance, suppose we have four classes A, B, C and D. Class A can inherit to B, B to C and C can inherit to D and so on now class D has all public members of class A, B and C include its own.

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd