Showing posts with label Types of Array. Show all posts
Showing posts with label Types of Array. Show all posts

Sunday, December 16, 2012


Multi-Dimensional Array: VB.Net मे कई dimensions के array create किए जा सकते हैं। ऐसे array जिसमे एक से जायदा subscripts होती हैं उन्हे multi-dimensional array कहते हैं। MD array को declare करने के लिए भी Dim, private या public statement का use किया जाता है। इसे declare करते समय इसमे एक से ज्यादा subscripts दी जाती हैं। यह subscripts के multiple के बराबर values store कर सकते हैं जैसे n(2,3) array मे 6 values store की जा सकती हैं।


Syntax:
Dim <array name> (script1, script2 ...) As <Data Type>
Exp-
Dim matrix (3, 3) as Integer
Dim T (2, 3, 4, 2) As Double
Initializing Multi-Dimensional Array:
MD Array को initialize करने के लिए Carly braces का use करते हैं।
Dim n (3, 3) As Integer = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mat(3, 3) As Integer
        Dim i, j As Integer
        'Take Input

        For i = 0 To 2
            For j = 0 To 2
                mat(i, j) = InputBox("Enter value on Matrix")
            Next
        Next
        'Printing Matrix
        Label1.Text = ""
        For i = 0 To 2
            For j = 0 To 2
                Label1.Text = Label1.Text & "   " & mat(i, j)
            Next
            Label1.Text = Label1.Text & Chr(13)
        Next

    End Sub
End Class

Visual Basic मे Array दो प्रकार के होते हैं।
i. One Dimensional Array
ii. Multi-Dimensional Array
  • One Dimensional Array: ऐसे array जिसमे केवल एक index या subscript होती है उसे one dimensional array कहते हैं। इसमे multiple values को स्टोर किया जा सकता है। इसमे array मे कोई value store करने या access करने के लिए इसकी index का use किया जाता है। जैसे-
Dim marks (10) As Integer
इस declaration मे marks array मे 0 से 9 index तक या 10 values store की जा सकती हैं।
Initializing one dimensional Array: 1D array मे design और run time दोनों मे values को insert किया जा सकता है।
Design time मे value store करने के लिए array index या Carly brackets {} का use किया जाता है।
Syntax:
Dim array_name() As DataType = {element1, element2,….}
Exp-
Dim name () As String = {“Raj”, “Shyam”, “Ashu”}
या
Dim Name (2) As String
Name (0) = “Raj”
Name (1) = “Shyam”
Name(2) = “Ashu”











image
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a(5) As Integer
Dim i As Integer
For i = 0 To 4
a(i) = InputBox("Enter Value")
Label1.Text = Label1.Text & Chr(13) & a(i)
Next
End Sub
End Class










Monday, August 13, 2012


Arrays: 
array एक standard structure है जो की data को store करने के लिए use किया जाता है। individual variable केवल एक ही value को store करता है जबकि array data के set को store करने के लिए प्रयोग किया जाता है। इसमे single variable मे एक से ज्यादा डाटा store किया जा सकता है। जैसे – a set of numbers, a series of dates etc.

Array is used to hold a set of data of the same type.

Array variable मे value store करने और access करने के लिए array की index का use किया जाता है।

Declaring Array: 
simple variable की तरह ही array को भी Dim, private या public statement का use कर declare किया जाता है। इसे declare करते समय array के नाम के बाद parentheses मे array की last index की value दी जाती है। जिसे subscript, index या size कहते हैं

Syntax: Dim <array name > (subscript) As <Data Type>

Exp-   Dim employee_name (20) As String

      Dim salary (20) As Integer 

Contact us

Name

Email *

Message *