我只是想知道,因为这段代码的代码复杂度为 16,如果我想在 CC 上达到完美的 9/10,最好的方法是什么?我知道它不会杀了我,但我很想知道其他人是否会以不同的方式编写这段代码
class SentMessages
{
public SentMessages() { }
public SentMessages(int id, string userName, string message, string messageType, DateTime createdAt)
{
this.Id = id;
this.UserName = userName;
this.Message = message;
this.CreatedAt = createdAt;
this.MessageType = messageType;
}
public string UserName { get; set; }
public int Id { get; set; }
public string Message { get; set; }
public string MessageType { get; set; }
public DateTime CreatedAt { get; set; }
public List<SentMessages> GetMessages()
{
if (AllMessages.Count == 0) AllMessages = SentMessages.InitializeMessages();
return AllMessages;
}
public List<SentMessages> AllMessages = new List<SentMessages>();
static private List<SentMessages> InitializeMessages()
{
List<SentMessages> messages = new List<SentMessages>();
return messages;
}
public void ClearMessages()
{
AllMessages.Clear();
}
}
我从http://objectlistview.sourceforge.net/cs和 stackoverlfow 答案中获得了此代码的概念