Click here to Skip to main content
15,902,887 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# timesheet business logic question Pin
Sascha Lefèvre19-Apr-15 12:25
professionalSascha Lefèvre19-Apr-15 12:25 
QuestionHow do I add 3 objects to array in C# Pin
Aindriu Mac Giolla Eoin19-Apr-15 8:27
Aindriu Mac Giolla Eoin19-Apr-15 8:27 
AnswerRe: How do I add 3 objects to array in C# Pin
Sascha Lefèvre19-Apr-15 8:31
professionalSascha Lefèvre19-Apr-15 8:31 
GeneralRe: How do I add 3 objects to array in C# Pin
Aindriu Mac Giolla Eoin19-Apr-15 8:33
Aindriu Mac Giolla Eoin19-Apr-15 8:33 
GeneralRe: How do I add 3 objects to array in C# Pin
Sascha Lefèvre19-Apr-15 8:38
professionalSascha Lefèvre19-Apr-15 8:38 
GeneralRe: How do I add 3 objects to array in C# Pin
Aindriu Mac Giolla Eoin19-Apr-15 8:44
Aindriu Mac Giolla Eoin19-Apr-15 8:44 
GeneralRe: How do I add 3 objects to array in C# Pin
PIEBALDconsult19-Apr-15 9:01
mvePIEBALDconsult19-Apr-15 9:01 
GeneralRe: How do I add 3 objects to array in C# Pin
Sascha Lefèvre19-Apr-15 9:03
professionalSascha Lefèvre19-Apr-15 9:03 
I assume you've put the assignment into the class-scope, like so (15th line or so):
C#
Public class Course
{
    private string courseName;
 
    public string CourseName
    {
        get { return courseName; }
        set { courseName = value; }
    }

    // this would be ok, because it's a "declaration" like "private string courseName;" above
    Student[] studentarray = new Student[3]; 

    // this isn't a declaration and can't exist directly in the class scope:
    studentarray[0] = student1;

    // instead theoretically something like this (within a methods scope):
    public void SomeMethod()
    {
        studentarray[0] = student1;
        // "theoretically" because "student1" isn't known here
    }
    
    // makes a tiny bit more sense:
    public void SetStudent0(Student student)
    {
        studentarray[0] = student;
        // only a tiny bit because this method would have the fixed purpose
        // of assigning to array index 0
    }
    // you would call it outside of this class like so: someCourse.SetStudent0(student1);

    // some more sense:
    public void SetStudent(Student student, int index)
    {
        studentarray[index] = student;
        // only some more sense because from outside this class you don't know which
        // array indices would be valid
    }
    // you would call it outside of this class like so: someCourse.SetStudent(student1, 0);

    // even more sense:
    private int ArrayCursor = 0;
    public void AddStudent(Student student)
    {
        studentarray[ArrayCursor] = student;
        ArrayCursor++;
        // will only work as long as there's enough space in the array
    }
    // you would call it outside of this class like so: someCourse.AddStudent(student1);

    // best with a generic list:
    private List<Student> Students = new List<Student>();
    public void AddStudent(Student student)
    {
        Students.Add(student);
    }
}

If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

GeneralRe: How do I add 3 objects to array in C# Pin
Aindriu Mac Giolla Eoin19-Apr-15 9:13
Aindriu Mac Giolla Eoin19-Apr-15 9:13 
GeneralRe: How do I add 3 objects to array in C# Pin
Sascha Lefèvre19-Apr-15 9:16
professionalSascha Lefèvre19-Apr-15 9:16 
GeneralRe: How do I add 3 objects to array in C# Pin
Aindriu Mac Giolla Eoin19-Apr-15 9:24
Aindriu Mac Giolla Eoin19-Apr-15 9:24 
GeneralRe: How do I add 3 objects to array in C# Pin
Sascha Lefèvre19-Apr-15 9:27
professionalSascha Lefèvre19-Apr-15 9:27 
GeneralRe: How do I add 3 objects to array in C# Pin
Aindriu Mac Giolla Eoin19-Apr-15 9:32
Aindriu Mac Giolla Eoin19-Apr-15 9:32 
QuestionGoogle Spreadsheets API - Getting Data into dataGridView? Pin
Linus Agren19-Apr-15 6:00
Linus Agren19-Apr-15 6:00 
AnswerRe: Google Spreadsheets API - Getting Data into dataGridView? Pin
Linus Agren20-Apr-15 18:04
Linus Agren20-Apr-15 18:04 
QuestionCatch Win+Left (Aero-Snap)? Pin
SledgeHammer0118-Apr-15 16:01
SledgeHammer0118-Apr-15 16:01 
AnswerRe: Catch Win+Left (Aero-Snap)? Pin
Dave Kreskowiak18-Apr-15 18:47
mveDave Kreskowiak18-Apr-15 18:47 
GeneralRe: Catch Win+Left (Aero-Snap)? Pin
SledgeHammer0118-Apr-15 20:19
SledgeHammer0118-Apr-15 20:19 
SuggestionRe: Catch Win+Left (Aero-Snap)? Pin
Richard Deeming20-Apr-15 2:34
mveRichard Deeming20-Apr-15 2:34 
QuestionHow do I add an object to a list within a class? Pin
Doncal18-Apr-15 9:43
Doncal18-Apr-15 9:43 
AnswerRe: How do I add an object to a list within a class? Pin
Pete O'Hanlon18-Apr-15 10:06
mvePete O'Hanlon18-Apr-15 10:06 
AnswerRe: How do I add an object to a list within a class? Pin
Sascha Lefèvre18-Apr-15 10:09
professionalSascha Lefèvre18-Apr-15 10:09 
AnswerRe: How do I add an object to a list within a class? Pin
Doncal18-Apr-15 10:24
Doncal18-Apr-15 10:24 
GeneralRe: How do I add an object to a list within a class? Pin
Sascha Lefèvre18-Apr-15 10:27
professionalSascha Lefèvre18-Apr-15 10:27 
GeneralRe: How do I add an object to a list within a class? Pin
BillWoodruff18-Apr-15 17:28
professionalBillWoodruff18-Apr-15 17:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.