Can someone please review my solution to the StackOverFlow exercise for C#.
using System;
namespace StackOverflow
{
public class Post
{
public string _title;
public string _description;
public DateTime _dateCreated;
private int _upVote= 0;
private int _downVote = 0;
public Post(string title, string description, DateTime datetime)
{
this._title = title;
this._description = description;
this._dateCreated = datetime;
}
public int UpVote()
{
return _upVote += 1;
}
public int DownVote()
{
_downVote--;
if(_downVote < 0)
{
_downVote = 0;
}
return _downVote;
}
}
class Program
{
static void Main(string[] args)
{
Post post1 = new Post("Hello", "This is my post", new DateTime(2023, 12, 31));
Console.WriteLine("Post Title: {0}\n Post Description: {1}\n Date Created: {2}", post1._title, post1._description, post1._dateCreated);
Console.WriteLine("Enter Vote. Choose 1 for UpVote, 0 for DownVote: ");
var choice = Convert.ToInt32(Console.ReadLine());
if (choice == 1)
{
var upVoteCount = post1.UpVote();
Console.WriteLine("Your Upvote = " + upVoteCount);
}
if (choice == 0)
{
var downVoteCount = post1.DownVote();
Console.WriteLine("Your DownVote = " + downVoteCount);
}
}
}
}