示例#1
0
        static void Main(string[] args)
        {
            var post = new Post("HelloWorld", "This is my implementation of a mock StackOverFlow post.");

            Console.WriteLine("The date and time of the creation of this post is: {0}", post.DateTimeOfCreation.ToString());

            // let's up-vote/down-vote this post n times, then display its vote value
            var upvotes   = 0;
            var downvotes = 0;

            try
            {
                Console.WriteLine("How many times would you like to up-vote this post?");
                upvotes = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("How many times would you like to down-vote this post?");
                downvotes = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                throw new Exception("Input must be an integer");
            }
            for (int i = 0; i < upvotes; i++)
            {
                post.Upvote();
            }

            for (int i = 0; i < downvotes; i++)
            {
                post.Downvote();
            }

            Console.WriteLine("This post has a vote value of: {0}", post.GetVoteValue());
        }
        static void Main(string[] args)
        {
            try
            {
                var post = new Post("How do I remove a particular element from an array in JavaScript?", "Is there a simple way to remove a specific element from an array? I have to use core JavaScript -no frameworks are allowed.");
                post.Upvote(); post.Upvote(); post.Upvote(); post.Upvote(); post.Upvote();
                Console.WriteLine("Welcome to StackOverflow");
                Console.WriteLine("Title: {0}", post.Title);
                Console.WriteLine("Description: {0}", post.Description);
                Console.WriteLine("Press 1 to upvote and 0 to downvote this post.");
                int vote = Convert.ToInt32(Console.ReadLine());
                if (vote == 1)
                {
                    post.Upvote();
                }
                else
                {
                    post.Downvote();
                }

                Console.WriteLine("Votes: {0}", post.Votes);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Post title and description can't be blank.");
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            var post = new Post("Hello", "World");

            System.Console.WriteLine($"{post.Title} {post.Description} {post.TimeCreated} {post.Score}");
            post.Upvote();
            post.Upvote();
            post.Upvote();
            post.Upvote();
            post.Downvote();
            System.Console.WriteLine($"{post.Title} {post.Description} {post.TimeCreated} {post.Score}");
            post.Downvote();
            post.Downvote();
            post.Downvote();
            post.Downvote();
            System.Console.WriteLine($"{post.Title} {post.Description} {post.TimeCreated} {post.Score}");
        }
示例#4
0
        static void Main(string[] args)
        {
            Post myPost = new Post("Help, I need something", "there is a problem, here it is. Help.");

            for (int i = 0; i < 10; i++)
            {
                myPost.Upvote();
            }
            myPost.Downvote();
            Console.WriteLine("Score: {0}", myPost.Score);
        }