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 SinghRank #1,805 · 824 reputationPosted Dec 13, 2015, 8:12 PM EST
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();
}
}
Ranjit PowarRank #553 · 4.4K reputationPosted Dec 13, 2015, 5:00 PM EST
MahaRank #2,573 · 543 reputationPosted Dec 13, 2015, 5:34 PM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Dec 13, 2015, 6:19 PM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Dec 13, 2015, 7:14 PM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Dec 13, 2015, 7:46 PM EST
Rupali ShindeRank #539 · 4.5K reputationPosted Dec 13, 2015, 8:36 PM EST
Sujeet SumanRank #790 · 2.9K reputationPosted Dec 13, 2015, 8:53 PM EST
MahaRank #2,573 · 543 reputationPosted Dec 13, 2015, 11:10 PM EST
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.
Rajesh SinghRank #1,805 · 824 reputationPosted Dec 13, 2015, 11:31 PM EST