Initialisation of structures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonia.sardana
    New Member
    • Jul 2006
    • 95

    Initialisation of structures

    I want to ask that as in C, we can initilase the structures as in the follwoing example, Is it also possible to do same in Vb.net. I have tried but error is coming.

    C Example
    #include<stdio. h>
    #include<conio. h>

    void main()
    {
    struct student
    {
    int roll;
    char grade[5];
    } ;

    struct student s1={1,"a"};
    clrscr();
    printf("%d %s",s1.roll,s1. grade);
    getch();
    }


    VB.Net Example
    Module Module1
    Public Structure student
    Public roll As Integer
    Public name As String
    End Structure

    Sub Main()
    Dim obj As student = {1, "sonia"}
    Console.WriteLi ne(obj.roll)
    Console.WriteLi ne(obj.name)
    Console.ReadLin e()
    End Sub
    End Module
Working...