Exemple #1
0
        public VoteEventArgs Vote(string question)
        {
            VoteEventArgs voteEventArgs = new VoteEventArgs();

            Console.WriteLine(question);
            voteEventArgs.Question = question;
            onVote(this, voteEventArgs);
            return(voteEventArgs);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            ElectoralComission electoralComission = new ElectoralComission();
            int n = 10;

            Voter[] voters = new Voter[n];
            for (int i = 0; i < n; i++)
            {
                voters[i] = new Voter();
                electoralComission.onVote += voters[i].VoterHandler;
            }
            VoteEventArgs voteEventArgs = electoralComission.Vote("???");

            Console.WriteLine(voteEventArgs.VoteFor);
            Console.WriteLine(voteEventArgs.VoteAgainst);
            Console.WriteLine(voteEventArgs.VoteAbstained);
        }
Exemple #3
0
        public void VoterHandler(object sender, VoteEventArgs e)
        {
            int num = random.Next(0, 3);

            if (num == 0)
            {
                e.VoteFor++;
            }
            else if (num == 1)
            {
                e.VoteAgainst++;
            }
            else
            {
                e.VoteAbstained++;
            }
        }