Array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Array

I want to create an array contains variables in different class like this codes: internal class Students { public string Stdname; int Credit_hours; int id; string dept; Course []courses; string DateOfBirth; public Students(string name, int id ,string DateOfBirth,Course[]courses) { this.Stdname = name; this.id = id; this.DateOfBirth = DateOfBirth; this.courses = courses; } public void print(Course[] courses, Func<Course, bool> filter, params int[] courseIDs) { Console.WriteLine("|name: "+Stdname+"|ID: "+id+"|The Date Of Birth"+ DateOfBirth +"|Courses:" ); foreach (Course course in courses) { if (filter(course) && courseIDs.Contains(course.CourseId)) { Console.WriteLine("|Course ID: " + course.CourseId + "|Course Name: " + course.CourseName); } } } }

26th Apr 2024, 3:07 AM
‎Sohaila Sherif Omar
‎Sohaila Sherif Omar - avatar
1 Answer
+ 1
in c# arrays contain homogeneous elements; inside the class give all the visibility, otherwise those are private by default. and try to use PascalCase. note: if you don't know how many elements will you use maximally, then don't use arrays, use list instead.... internal class Students { private Students() { this.Students = new List<Students>(); // load it from file (csv), for the first time } public List<Students> Students; // and use properties (getters and setters) }
26th Apr 2024, 2:10 PM
Mihaly Nyilas
Mihaly Nyilas - avatar