Count number of males and females in a list of students

Dev999

New member
Joined
May 20, 2021
Messages
1
Programming Experience
Beginner
Hi everyone. I am new to C# and I am trying to solve some basic exercises. I got stuck in this exercise. We have a classs student with two parameters string : Name string : Gender. And we have two list with students. We need to return the number of students males and females but we shpuld use ref to return multiple values in this function. I have done the code below. Can you help me ? I appreciate it.

list:
using System;
using System.Collections.Generic;
namespace ExerciseGeneric
{
    class Program
    {
        public string name;
        public string gender;

        static void Main(string[] args)
        {
            List<Student> listStudents1 = new List<Student>()
            {
                new Student("atr","f"),
                new Student("ar","f"),
                new Student("rrbr","f"),
                new Student("ar","f"),
                new Student("atr","f"),
                new Student("arr","f"),
                new Student("ajr","f"),
                new Student("an","f"),
                new Student("ytr","f"),
                new Student("ktr","f"),
            };


            List<Student> listStudents2 = new List<Student>()
            {
                new Student("atr","f"),
                new Student("atr","f"),
                new Student("atr","f"),
                new Student("uyr","f"),
                new Student("edr","f"),
                new Student("sddfr","f"),
                new Student("atxar","f"),
                new Student("ytadr","f"),
                new Student("usr","f"),
                new Student("stfr","f"),
            };
 
As with all programming problems, start by pretending that it is not a programming problem. What are the exact steps you would perform if it was a manual problem? Those are the very same steps that your code needs to perform, so that is how you work out the logic required. No programming experience is required for that part. At the very least, you should be able to come up with an algorithm by doing that. You can start with a few vague steps but you need to spend time thinking about specifics, so break each step down into the smallest parts you can and make every part specific. Until you have done that, it's not actually a programming problem.

Once you have an algorithm, you can treat each step independently, like a series of boxes that you connect together with pipes. If you are having trouble with one step then you can leave it for the time being and try another. Once you've implemented all the steps you can, you can then show us your algorithm and the code that you have so far, explaining exactly which step you're stuck on and why. We then have a specific problem we can help you with.
 
Back
Top Bottom