i have this code
private static Func<fLogin,BusinessObject.User> Make = f =>
new BusinessObject.Usuario {
Name = f.txtU.Text,
Pass = f.txtPass.Text,
};
So. the User class is this.
public class User
{
public string Name {get; set; }
public string Pass {get; set; }
public Company Com {get; set; }
}
and the user has a Company
here’s company
public class Company
{
public string CompanyName {get; set;}
}
so, here is the issue, when i want to access company name, gives me error
private static Func<fLogin,BusinessObject.User> Make = f =>
new BusinessObject.Usuario {
Name = f.txtU.Text,
Pass = f.txtPass.Text,
Com.CompanyName = f.txtC.text
};
Com.CompanyName = f.txtC.text
this is not possible?
The reason that you’re getting an error on
is that you have to set the
Comproperty in the object initializer, not set theCompanyNameproperty on theComproperty. The fix is to use a nested object initializer to setComto a newCompanywith the correctCompanyNameproperty: