示例#1
0
        public VetoEventArgs Vote(string Proposal)
        {
            VetoEventArgs vetoVoteArgs = new VetoEventArgs(Proposal);

            OnVote?.Invoke(this, vetoVoteArgs);
            return(vetoVoteArgs);
        }
示例#2
0
        public void VetoVote(object sender, VetoEventArgs e)
        {
            Random rand = new Random();

            if (e.VetoBy != null)
            {
                return;
            }
            if (rand.Next(0, 5) == 1)
            {
                e.VetoBy = this;
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            VetoComission vetoCom = new VetoComission();

            VetoVoter[] voters     = new VetoVoter[5];
            string[]    voterNames = { "John", "Albert", "Giovanni", "Elisa", "Sean" };

            for (int i = 0; i < voters.Length; i++)
            {
                voters[i]       = new VetoVoter(voterNames[i]);
                vetoCom.OnVote += voters[i].VetoVote;
            }

            VetoEventArgs voteResults = vetoCom.Vote("Lifting lockdown");

            Console.WriteLine($"Proposal: {voteResults.Proposal}. Vote result: {(voteResults.VetoBy == null ? "Approved" : "Vetoed")}.");
            if (voteResults.VetoBy != null)
            {
                Console.WriteLine($"Vetoed by: {voteResults.VetoBy.Name}.");
            }
        }