C#C
C#3y ago
Dinny

I am unaware on how to fix this conversion error

it's saying i can't convert from string to int, though I am unsure why when i used the string.format method to represent my int variable ID as a string and display it in my output file. I have three separte files for a regular user logging in, an administrator, and thena file to put the whole program together.
here is admin and the full program since that is where the issue lies
using System;
using System.Globalization;
using System.IO;


namespace LogIn
{
    public class Administrator : RegularUser
    {
        //data fields
        private int ID;


        public Administrator(int ID = 0, string userName = " ") : base(userName)
        {
            //data fields
            this.ID = ID;
        }

        //GETTER
        /**
         Returns the ID of the admin
        @return: admin's ID
         */
        public int GetID() { return ID; }


        //SETTERS
        /**
         Returns an updated ID number
        @return: admin's updated ID number
         */
        public void SetID(int ID) { this.ID = ID; }

        //sign-in method
        public new static void SignIn(string dateAndTime, StreamWriter writer)
        {
            writer.WriteLine("signed in @ {1}", dateAndTime);
        }

        //sign out method
        public new static void SignOut(string dateAndTime, StreamWriter writer)
        {
            writer.WriteLine("signed out @ {1}", dateAndTime);
        }


        /** Returns the user's username and ID in string format and whether they've signed in/out
          @return: a string representing who signed in/out along with ther ID #
      */
        public override string Stringify()
        {
            return string.Format("({1}) ", base.Stringify(), GetID());
        }

        public override string Stringify2()
        {
            return string.Format("({1}) ", base.Stringify2(), GetID());
        }


    }


}
Was this page helpful?