You need to create an instance of your class to access its properties and methods.
StudentRecord student = new StudentRecord();
student.ToString();
Question
namespace StudentSearch
{
public class StudentRecord : IEquatable<StudentRecord>
{
public string StudentID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Gender { get; set; }
public string State { get; set; }
public int? Age { get; set; }
public decimal? GPA { get; set; }
public override string ToString()
{
return string.Format("{0,-11}{1,-25}{2,3:d} {3,-7}{4,-11}{5:n2}",
StudentID, (FirstName + " " + LastName), Age, Gender, State, GPA);
}
}
partial class frmStudentSearch
{
HashSet<StudentRecord> hsAllStudents = new HashSet<StudentRecord>(){
new StudentRecord {StudentID = "G00002728", LastName = "Bryant", FirstName = "Tim", Gender = "M", State = "UT", Age = 47, GPA = 3.98M},
-sic-
};
}
That piece of code is stored in ModNames.cs under the StudentSearch namespace, in public class StudentRecord
I'm trying to make a call from public partial class StudentSearch : Form, to StudentRecord to take this data, check it's validity, then display it in a DataDisplayGrid.
Thing is, I haven't really dealt with multiple classes, or class to other classes in c# or generally programming much before and this is kind of throwing me for a loop.
I tried to just make a call using variations on
StudentRecord.ToString();
I haven't really messed with string.format before either, so doing it between classes is throwing me for a loop, both on the syntax to correctly call this method, and how to type/hold the data.
The information has to be out there on the 'net somewhere, but I just can't find the right search terms on stackoverflow or google to turn up an answer as to how I do this.
I've checked msdn, but if I've come across the answer, I didn't realize it.
Solution
You need to create an instance of your class to access its properties and methods.
StudentRecord student = new StudentRecord();
student.ToString();