Answer the question
In order to leave comments, you need to log in
How to write a class for users?
Good afternoon. Need help understanding how to create a class that will act as a repository for comments from users. This is not a combat application and never will be. Rather, for a general understanding of how it works.
public class User
{
public int UserID;
public string NickName;
public string HomeTown;
public string BirthDate;
public string DateOfRegistration;
public UserRole Role;
public User(int userid,string nickname,string hometown,string birthdate, string date_of_registration, UserRole role)
{
this.UserID = userid;
this.NickName = nickname;
this.HomeTown = hometown;
this.BirthDate = birthdate;
this.DateOfRegistration = date_of_registration;
this.Role = role;
}
public override string ToString()
{
return $"UserID --> {UserID}\nNickName --> {NickName}\nNomeTown --> {HomeTown}\nBirthDate --> {BirthDate}\nDateOfRegistration --> {DateOfRegistration}\nUserRole --> {Role}";
}
}
public enum UserRole : byte
{
Administrator,
Moderator,
DefaultUser,
}
public class UserContent
{
public int ContentID;
public string Content;
public User Author;
public string ContentTime;
public UserContent(int content_id, string content, User author, string content_time)
{
this.ContentID = content_id;
this.Content = content;
this.Author = author;
this.ContentTime = content_time;
}
public override string ToString()
{
return $"ID Статьи --> {ContentID}\nСтатья --> {Content}\nАвтор статьи --> {Author.NickName}\nДата создания --> {ContentTime}";
}
}
static void Main(string[] args)
{
List<User> users = new List<User>();
users.Add(new User(1,"Morpheus","Zion","Dec 15,1985","Jan 12, 2010",UserRole.Administrator));
users.Add(new User(2,"Trinity","Zion","May 10,1980","Sep 6, 2012", UserRole.Administrator));
users.Add(new User(3,"Apok","Zion","Mar 22,1970" , "Feb 11, 2011", UserRole.Moderator));
users.Add(new User(4,"Neo", "Los-Angeles","Jul 2,1982", "Dec 7,2012", UserRole.DefaultUser));
List<UserContent> content = new List<UserContent>();
content.Add(new UserContent(1, "Hello Zion!", new User("Morpheus"), "May 24,2018"));
Console.ReadKey();
}
content.Add(new UserContent(1, "Hello Zion!", new User("Morpheus"), "May 24,2018"));
Answer the question
In order to leave comments, you need to log in
var theUser = new User("Morpheus");
content.Add(new UserContent(1, "Hello Zion!", theUser, "May 24,2018"));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question