structure Array

4 views
Skip to first unread message

Fateme AsnaAshary

unread,
Aug 22, 2012, 6:38:25 PM8/22/12
to computer_asso...@googlegroups.com
با عرض سلام حضور شما استاد گرامی
و ضمن تشکر از زحماتتان.
من یه struct تعریف کردم. به شکل زیر
  public struct Student
        {
            public string Name, Family;
            public double[] Mark;
            public double Average;
            public Student(int n)
            {
                Name = "";
                Family = "";
                Average = 0;
                Mark = new double[n];
            }
        }

و می خوام یه آرایه از این struct تعریف کنم .ولی نمیشه هم آرایه تعریف کنم و هم تابع سازندشو فراخوانی کنم. برای این کار، این خط رو نوشته بودم:
Student[] std= new Student(10)[n];
ولی خطا میده و نمیدونم باید چه کنم.
 error:   Cannot apply indexing with [] to an expression of type Student

اگه من رو راهنمایی ممنون میشم.
متشکرم

--
Fateme AsnaAshary

ali baie

unread,
Aug 23, 2012, 9:23:57 AM8/23/12
to computer_asso...@googlegroups.com
 Student[] obj1 = new Student[2];
            //یا
            Student[] obj2=new Student[]
                {
                    new Student(4),
                    new Student(5)
                };
در حالت اول یک آرایه با دو خانه دارید که تابع سازنده را در این حالت نمی توانید فراخوانی کنید
در حالت دوم یک آرایه دو حانه ای دارید که به صورتی که مشاهده می کنید تابع سازنده را باید فراخواین کنید
موفق باشید و سربلند

valadkhan

unread,
Aug 23, 2012, 9:26:24 AM8/23/12
to computer_asso...@googlegroups.com
این چیه؟
Reply all
Reply to author
Forward
0 new messages