Answer to Question #180967 in C# for Muhammmad Arfan

Question #180967

Define a class (Name, Father name, Roll num, session, GPA, address, 

semester) and store the record of 10 students in c# windows Application.

One should be able to search by name, roll num, session and GPA.

Searched data should be displayed in the decesding order


1
Expert's answer
2021-04-13T15:08:24-0400
using System.Linq;
public class User
{
    public string name;
    public string nameFather;
    public int numRoll;
    public float session;
    public float gap;
    public string address;
    public float semester;
}
public class Main
{
    public void Metod()
    {
        List<User> users = new List<User>
        {
            new User
            {
                name = "Austin",
                nameFather = "William",
                numRoll = 1,
                session = 3,
                gap = 3f,
                address = "3125 Galena Ave",
                semester = 3.5f
            },
            new User
            {
                name = "Olivia",
                nameFather = "Joseph",
                numRoll = 2,
                session = 3,
                gap = 2f,
                address = "4155 Racine St",
                semester = 3.5f
            },
            new User
            {
                name = "Ryan",
                nameFather = "James",
                numRoll = 3,
                gap = 5f,
                session = 4,
                address = "3215 Racine St",
                semester = 5f
            },
            new User
            {
                name = "Zoe",
                nameFather = "Thomas",
                numRoll = 4,
                gap = 4f,
                session = 5,
                address = "3335 Galena Ave",
                semester = 5f
            },
            new User
            {
                name = "Ivy",
                nameFather = "Harry",
                numRoll = 5,
                gap = 3f,
                session = 3,
                address = "5525 Racine St",
                semester = 3.5f
            },
            new User
            {
                name = "Rose",
                nameFather = "Harry",
                numRoll = 6,
                gap = 4f,
                session = 4,
                address = "3312 Waldo St",
                semester = 4f
            },
            new User
            {
                name = "Stanley",
                nameFather = "Joseph",
                numRoll = 7,
                session = 3,
                gap = 3f,
                address = "5212 Waldo St",
                semester = 3.5f
            },
            new User
            {
                name = "Dexter",
                nameFather = "Leo",
                numRoll = 9,
                session = 3,
                gap = 3f,
                address = "2221 Galena Ave",
                semester = 3.5f
            },
            new User
            {
                name = "Olivia",
                nameFather = "Joseph",
                numRoll = 8,
                session = 2,
                gap = 3f,
                address = "3165 Galena Ave",
                semester = 2f
            },
            new User
            {
                name = "Noah",
                nameFather = "George",
                numRoll = 10,
                session = 3,
                gap = 4f,
                address = "6212 Waldo St",
                semester = 4f
            }
        };
        users = users.Where(x => x.name == "Olivia").ToList(); // Search by name
        users = users.Where(x => x.numRoll == 1).ToList(); // Search by numRoll
        users = users.Where(x => x.session == 4f).ToList(); // Search by session
        users = users.Where(x => x.gap == 3f).ToList(); // Search by gap
    }
}

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