mardi 7 mars 2017

C# Randomizing the ID

I seem to be having trouble with the ID part of my programming. Whenever I run it, it will say that the Student ID is 0. I'm trying to make it where it will call a randomized number between 1000 and 9999. Could someone please tell me where I am going wrong and how to go about fixing it?

class Program
{
    static void Main(string[] args)
    {
        List<Student> myList = new List<Student>();


        Student s1 = new Student();
        s1.firstName = "John";
        s1.lastName = "Smith";
        s1.sID = 2560;
        myList.Add(s1);

        Student s2 = new Student("Peter ");
        myList.Add(s2);


        Student s3 = new Student("John", "Smith");
        myList.Add(s3);

        Student s4 = new Student("Peter", "Pines");
        myList.Add(s4);


        Student s5 = new Student("Morgan", "Simmons");
        myList.Add(s5);

        Student s6 = new Student("James", "Walters");
        myList.Add(s6);

        Student s7 = new Student("Linda", "Scott", 1005);
        myList.Add(s7);


        Console.WriteLine();

        Console.WriteLine("Total students: {0}", Student.Count);            

    }
class Student
{
    private static int count = 0; 
    private string v;
    private int v1;
    private static readonly Random rnd = new Random();

    public string FirstName { get; private set; }


    public string LastName { get; private set; }

    public Student(string first, string last)
    {
        FirstName = first;
        LastName = last;
        count++;
        sID = sID;
        Console.WriteLine("Student Name: {0} {1}; Student ID {3}; count = {2}",
           FirstName, LastName, Count, sID);
    } 
    public Student()
    {
    }

    public Student(string v)
    {
        this.v = v;
    }

    public Student(string first, string last,  int v1) : this(first, last)
    {
        this.v1 = v1;
    }        
    public static int Count
    {
        get
        {
            return count;
        }
    }
    public static int SID
    {
        get
        {
            return sID;
        }
    }
    public string firstName { get; internal set; }
    public string lastName { get; internal set; }
    public int sID { get; internal set; }
}

Aucun commentaire:

Enregistrer un commentaire