Answer to Question #325624 in C# for Zarifa

Question #325624

Assign and print the roll number, phone number and address of two students having names "Sam" and "John" respectively by creating two objects of the class 'Student'. (For C sharp)


1
Expert's answer
2022-04-07T17:36:11-0400
internal class Program
    {
        class Student
        {
            public int RollNumber { get; set; }
            public string Name { get; set; }
            public int Phone { get; set; }
            public string Address { get; set; }


            public Student(int rollNumber, string name,int phone,string address)
            {
                RollNumber = rollNumber;
                Name = name;
                Phone = phone;
                Address = address;


            }

            public override string ToString()
            {
                return $"Roll Number: {RollNumber}; Name: {Name}; Phone: {Phone}; Address: {Address}";
            }
        }
        static void Main(string[] args)
        {
            List<Student> students = new List<Student>()
            {
                new Student(0,"Sam",123456789,"SamAddress"),
                new Student(1,"John",123456780,"JohnAddress")
            };
            foreach (Student student in students)
            {
                Console.WriteLine(student);
            }
            Console.ReadKey();
        }

    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS