is there a way to manipulate the properties of a Model into another property?
I need to generate the FullName based on the supplied LastName and FirstName properties of my Model.
public class User
{
public string Username { get; set; } = null!;
public string Role { get; set; } = null!;
public int EmployeeID { get; set; }
public string FullName { get; set; } = null!; //CONCAT FROM LastName & FirstName
public string LastName { get; set; } = null!;
public string FirstName { get; set; } = null!;
public Division Division { get; set; } = null!;
}
3
Answers
Simply use
public string FullName => LastName +" "+ FirstName;
instead of
public string FullName {get;set;}
.Also, there really is no need to specify
= null
as a default value for reference type properties – the default value of reference types is already null.Try:
You can concatenate
FirstName
andLastName
by making theFullName
property getter-only: