Originally this was a program with three-parameter constructor (parameter inside the round bracket) and executed well.
Student oneSophomore = new Student(951, "Ross", 3.5);
For curiosity I modified the program and placed the three-parameter inside the curly bracket. After that program is not executing. What corrections have to be done to execute the program.
Student oneSophomore = new Student(){idNumber=951, lastName="Ross", gradePointAverage=3.5};
using System;
public class CreateStudent_byMaha
{
public static void Main()
{
//Student oneSophomore = new Student(951, "Ross", 3.5);
Student oneSophomore = new Student(){idNumber=951, lastName="Ross", gradePointAverage=3.5};
Console.WriteLine
("The student named {0} has ID # is {1} and a gpa of {2}", oneSophomore.Name, oneSophomore.Id, oneSophomore.GPA);
Console.ReadKey();
}
}
class Student
{
private int idNumber;
private string lastName;
private double gradePointAverage;
public Student(int idNumber, string lastName, double gradePointAverage)
{
this.idNumber = idNumber;
this.lastName = lastName;
this.gradePointAverage = gradePointAverage;
}
public int Id
{
get { return idNumber; }
}
public string Name
{
get { return lastName; }
}
public double GPA
{
get { return gradePointAverage; }
}
}
//The student named Ross has ID # is 951 and a gpa of 3.5

Rajesh SinghPosted Dec 14, 2015, 1:12 AM
Hi Maha,
public class CreateStudent_byMaha
{
public static void Main()
{
//Student oneSophomore = new Student(951, "Ross", 3.5);
Student oneSophomore = new Student() { Id = 951, Name = "Ross", GPA = 3.5 };
Console.WriteLine
("The student named {0} has ID # is {1} and a gpa of {2}", oneSophomore.Name, oneSophomore.Id, oneSophomore.GPA);
Console.ReadKey();
}
}
Rajesh SinghPosted Dec 14, 2015, 4:31 AM
MahaPosted Dec 14, 2015, 4:10 AM
Rajesh Singh, Thank you for your explanation.
Jignesh Trivedi, you are also telling same thing but not in detail.
Rupali Shinde, your method is not executing also if fields are made public concept of information hiding is lost.
Sujeet Suman your method is not executing. Please tried to produce a complete program.
Sujeet SumanPosted Dec 14, 2015, 1:53 AM
Rupali ShindePosted Dec 14, 2015, 1:36 AM
Jignesh TrivediPosted Dec 14, 2015, 12:46 AM
Ranjit PowarPosted Dec 14, 2015, 12:14 AM
Ranjit PowarPosted Dec 13, 2015, 11:19 PM
MahaPosted Dec 13, 2015, 10:34 PM
Ranjit PowarPosted Dec 13, 2015, 10:00 PM