How do I add an object to a list in another class?Detecting an undefined object propertyHow do I check if a list is empty?What is the most efficient way to deep clone an object in JavaScript?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How to make a flat list out of list of listsChecking if a key exists in a JavaScript object?How do I get the number of elements in a list?How do I concatenate two lists in Python?How to clone or copy a list?
What was redacted in the Yellowhammer report? (Point 15)
What officially disallows US presidents from driving?
Does my opponent need to prove his creature has morph?
Relocation error involving libgnutls.so.30, error code (127) after last updates
If I want an interpretable model, are there methods other than Linear Regression?
Resume: How to quantify my contributions as a software engineer?
getting syntax error in simple bash script
How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?
Can I conceal an antihero's insanity - and should I?
Is there any way to land a rover on the Moon without using any thrusters?
Finding the number of digits of a given integer.
Percentage buffer around multiline in QGIS?
Uncovering the Accelerated Dragon opening
Newly created XFS filesystem shows 78 GB used
Parallel resistance in electric circuits
I was promised a work PC but still awaiting approval 3 months later so using my own laptop - Is it fair to ask employer for laptop insurance?
Where can I find vomiting people?
Why is the Digital 0 not 0V in computer systems?
A medieval fantasy adventurer lights a torch in a 100% pure oxygen room. What happens?
Difference in using Lightning Component <lighting:badge/> and Normal DOM with slds <span class="slds-badge"></span>? Which is Better and Why?
Should I leave the first authorship of our paper to the student who did the project whereas I solved it?
I asked for a graduate student position from a professor. He replied "welcome". What does that mean?
Telling my mother that I have anorexia without panicking her
Bash, import output from command as command
How do I add an object to a list in another class?
Detecting an undefined object propertyHow do I check if a list is empty?What is the most efficient way to deep clone an object in JavaScript?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How to make a flat list out of list of listsChecking if a key exists in a JavaScript object?How do I get the number of elements in a list?How do I concatenate two lists in Python?How to clone or copy a list?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I find myself unable to implement critical sections of my code for a project. The assignment is to develop the backend a text-based gradebook. I have a method, addStudent, which is supposed to add a student to a list in a section, also contained in a list.
I have a method in the Gradebook class, addStudent, which is supposed to add a student object to a list contained within the current Section object. The sections are also contained in a list. I have tried all sorts of combinations, but I can't seem to find the magic words that actually let me accomplish this.
The file is defined in 5 files/classes; Assignment(can be ignored for now), Student, Section, Gradebook, Program (also can ignore, only used for front end (input to pass to mehtods, etc.)).
Here is the method I need to implement, contained in the Gradebook class.
public bool addStudent(string firstName, string lastName, string username, long phoneNumber)
return false; //FIXME
Here is the Section Class:
class Section
string sectionName;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
List<Student> students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Here is the Student Class:
class Student
{
string firstName = null;
string lastName = null;
long studentID = 0;
long phoneNumber = 0;
int absentcount = 0;
int tardyCount = 0;
double gradePercent = 0;
//need to add more properties, read through Gradebook API for more
public Student(string firstName, string lastName, long studentID, long phoneNumber)
this.firstName = firstName;
this.lastName = lastName;
this.studentID = studentID;
this.phoneNumber = phoneNumber;
List<Assignment> studentAssignments = new List<Assignment>();
I am aware of the duplicate assignment definitions, I am keeping both in for now, likely for redundancy, though this might not be a great idea, in which case I will only keep the student version.
I expect to be able to just add some longer line referencing each object in the respective lists, but I always come up with an error, either that I need to make the fields read only, or that the object doesn't exist. The only solution I can think of would be to keep an index for the last modified element in the list, but I'd rather not do that.
I would logically think to do something like this (I know this is wrong): currentSection.Student.Add(Student(firstName, lastName, username, phoneNumber)). I know this can't be though, because I need to refernce the list element, not the class itself.
I also may just be overthinking this quite a bit but any help would be appreciated.
c# list object
add a comment
|
I find myself unable to implement critical sections of my code for a project. The assignment is to develop the backend a text-based gradebook. I have a method, addStudent, which is supposed to add a student to a list in a section, also contained in a list.
I have a method in the Gradebook class, addStudent, which is supposed to add a student object to a list contained within the current Section object. The sections are also contained in a list. I have tried all sorts of combinations, but I can't seem to find the magic words that actually let me accomplish this.
The file is defined in 5 files/classes; Assignment(can be ignored for now), Student, Section, Gradebook, Program (also can ignore, only used for front end (input to pass to mehtods, etc.)).
Here is the method I need to implement, contained in the Gradebook class.
public bool addStudent(string firstName, string lastName, string username, long phoneNumber)
return false; //FIXME
Here is the Section Class:
class Section
string sectionName;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
List<Student> students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Here is the Student Class:
class Student
{
string firstName = null;
string lastName = null;
long studentID = 0;
long phoneNumber = 0;
int absentcount = 0;
int tardyCount = 0;
double gradePercent = 0;
//need to add more properties, read through Gradebook API for more
public Student(string firstName, string lastName, long studentID, long phoneNumber)
this.firstName = firstName;
this.lastName = lastName;
this.studentID = studentID;
this.phoneNumber = phoneNumber;
List<Assignment> studentAssignments = new List<Assignment>();
I am aware of the duplicate assignment definitions, I am keeping both in for now, likely for redundancy, though this might not be a great idea, in which case I will only keep the student version.
I expect to be able to just add some longer line referencing each object in the respective lists, but I always come up with an error, either that I need to make the fields read only, or that the object doesn't exist. The only solution I can think of would be to keep an index for the last modified element in the list, but I'd rather not do that.
I would logically think to do something like this (I know this is wrong): currentSection.Student.Add(Student(firstName, lastName, username, phoneNumber)). I know this can't be though, because I need to refernce the list element, not the class itself.
I also may just be overthinking this quite a bit but any help would be appreciated.
c# list object
add a comment
|
I find myself unable to implement critical sections of my code for a project. The assignment is to develop the backend a text-based gradebook. I have a method, addStudent, which is supposed to add a student to a list in a section, also contained in a list.
I have a method in the Gradebook class, addStudent, which is supposed to add a student object to a list contained within the current Section object. The sections are also contained in a list. I have tried all sorts of combinations, but I can't seem to find the magic words that actually let me accomplish this.
The file is defined in 5 files/classes; Assignment(can be ignored for now), Student, Section, Gradebook, Program (also can ignore, only used for front end (input to pass to mehtods, etc.)).
Here is the method I need to implement, contained in the Gradebook class.
public bool addStudent(string firstName, string lastName, string username, long phoneNumber)
return false; //FIXME
Here is the Section Class:
class Section
string sectionName;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
List<Student> students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Here is the Student Class:
class Student
{
string firstName = null;
string lastName = null;
long studentID = 0;
long phoneNumber = 0;
int absentcount = 0;
int tardyCount = 0;
double gradePercent = 0;
//need to add more properties, read through Gradebook API for more
public Student(string firstName, string lastName, long studentID, long phoneNumber)
this.firstName = firstName;
this.lastName = lastName;
this.studentID = studentID;
this.phoneNumber = phoneNumber;
List<Assignment> studentAssignments = new List<Assignment>();
I am aware of the duplicate assignment definitions, I am keeping both in for now, likely for redundancy, though this might not be a great idea, in which case I will only keep the student version.
I expect to be able to just add some longer line referencing each object in the respective lists, but I always come up with an error, either that I need to make the fields read only, or that the object doesn't exist. The only solution I can think of would be to keep an index for the last modified element in the list, but I'd rather not do that.
I would logically think to do something like this (I know this is wrong): currentSection.Student.Add(Student(firstName, lastName, username, phoneNumber)). I know this can't be though, because I need to refernce the list element, not the class itself.
I also may just be overthinking this quite a bit but any help would be appreciated.
c# list object
I find myself unable to implement critical sections of my code for a project. The assignment is to develop the backend a text-based gradebook. I have a method, addStudent, which is supposed to add a student to a list in a section, also contained in a list.
I have a method in the Gradebook class, addStudent, which is supposed to add a student object to a list contained within the current Section object. The sections are also contained in a list. I have tried all sorts of combinations, but I can't seem to find the magic words that actually let me accomplish this.
The file is defined in 5 files/classes; Assignment(can be ignored for now), Student, Section, Gradebook, Program (also can ignore, only used for front end (input to pass to mehtods, etc.)).
Here is the method I need to implement, contained in the Gradebook class.
public bool addStudent(string firstName, string lastName, string username, long phoneNumber)
return false; //FIXME
Here is the Section Class:
class Section
string sectionName;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
List<Student> students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Here is the Student Class:
class Student
{
string firstName = null;
string lastName = null;
long studentID = 0;
long phoneNumber = 0;
int absentcount = 0;
int tardyCount = 0;
double gradePercent = 0;
//need to add more properties, read through Gradebook API for more
public Student(string firstName, string lastName, long studentID, long phoneNumber)
this.firstName = firstName;
this.lastName = lastName;
this.studentID = studentID;
this.phoneNumber = phoneNumber;
List<Assignment> studentAssignments = new List<Assignment>();
I am aware of the duplicate assignment definitions, I am keeping both in for now, likely for redundancy, though this might not be a great idea, in which case I will only keep the student version.
I expect to be able to just add some longer line referencing each object in the respective lists, but I always come up with an error, either that I need to make the fields read only, or that the object doesn't exist. The only solution I can think of would be to keep an index for the last modified element in the list, but I'd rather not do that.
I would logically think to do something like this (I know this is wrong): currentSection.Student.Add(Student(firstName, lastName, username, phoneNumber)). I know this can't be though, because I need to refernce the list element, not the class itself.
I also may just be overthinking this quite a bit but any help would be appreciated.
c# list object
c# list object
asked Mar 28 at 10:20
Jonathan ThadenJonathan Thaden
43 bronze badges
43 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
You should make your List<Student> students accessible from outside your Session constructor
Change your Section declaration to:
class Section
string sectionName;
public List<Student> students;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Add the student to your list with
currentSection.students.Add(new Student(firstName, lastName, username, phoneNumber));
As in moving the `List<Student> students outside the constructor but still in the same class, or moving it entirely different class?
– Jonathan Thaden
Mar 28 at 10:33
Only outside your constructor. I've included the needed code
– Aars93
Mar 28 at 10:34
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395157%2fhow-do-i-add-an-object-to-a-list-in-another-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should make your List<Student> students accessible from outside your Session constructor
Change your Section declaration to:
class Section
string sectionName;
public List<Student> students;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Add the student to your list with
currentSection.students.Add(new Student(firstName, lastName, username, phoneNumber));
As in moving the `List<Student> students outside the constructor but still in the same class, or moving it entirely different class?
– Jonathan Thaden
Mar 28 at 10:33
Only outside your constructor. I've included the needed code
– Aars93
Mar 28 at 10:34
add a comment
|
You should make your List<Student> students accessible from outside your Session constructor
Change your Section declaration to:
class Section
string sectionName;
public List<Student> students;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Add the student to your list with
currentSection.students.Add(new Student(firstName, lastName, username, phoneNumber));
As in moving the `List<Student> students outside the constructor but still in the same class, or moving it entirely different class?
– Jonathan Thaden
Mar 28 at 10:33
Only outside your constructor. I've included the needed code
– Aars93
Mar 28 at 10:34
add a comment
|
You should make your List<Student> students accessible from outside your Session constructor
Change your Section declaration to:
class Section
string sectionName;
public List<Student> students;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Add the student to your list with
currentSection.students.Add(new Student(firstName, lastName, username, phoneNumber));
You should make your List<Student> students accessible from outside your Session constructor
Change your Section declaration to:
class Section
string sectionName;
public List<Student> students;
//probably more properties need to be implemented, or at least would make life simpler
public Section(string sectionName)
this.sectionName = sectionName;
students = new List<Student>();
List<Assignment> assignments = new List<Assignment>();
Add the student to your list with
currentSection.students.Add(new Student(firstName, lastName, username, phoneNumber));
answered Mar 28 at 10:29
Aars93Aars93
3833 silver badges10 bronze badges
3833 silver badges10 bronze badges
As in moving the `List<Student> students outside the constructor but still in the same class, or moving it entirely different class?
– Jonathan Thaden
Mar 28 at 10:33
Only outside your constructor. I've included the needed code
– Aars93
Mar 28 at 10:34
add a comment
|
As in moving the `List<Student> students outside the constructor but still in the same class, or moving it entirely different class?
– Jonathan Thaden
Mar 28 at 10:33
Only outside your constructor. I've included the needed code
– Aars93
Mar 28 at 10:34
As in moving the `List<Student> students outside the constructor but still in the same class, or moving it entirely different class?
– Jonathan Thaden
Mar 28 at 10:33
As in moving the `List<Student> students outside the constructor but still in the same class, or moving it entirely different class?
– Jonathan Thaden
Mar 28 at 10:33
Only outside your constructor. I've included the needed code
– Aars93
Mar 28 at 10:34
Only outside your constructor. I've included the needed code
– Aars93
Mar 28 at 10:34
add a comment
|
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395157%2fhow-do-i-add-an-object-to-a-list-in-another-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown