I have created a list object
public IReadOnlyList? employeelist{ get; set; }
and I am assigning
public string EmployeeType =>
ContentTypes.GetemployeeType(employeelist?._manager, employeelist?.File.address?? string.Empty);
here am getting above error;--in (employeelist?._manager, employeelist?.File.address)
class i am using
public class employee:filedetails
{
public employee(IBrowserFile file)
{
File = file ?? throw new ArgumentNullException(nameof(file));
FileName = Path.GetFileName(File.Name);
}
public IBrowserFile File { get; }
}
how i can fix these?
Pasang TamangPosted Jan 5, 2023, 8:58 AM
Hi,
Yes, if you want to return only single item then you will need to convert list into single object by using FirstOrDefault(). If there is some condition that you need to apply while returning single object then you can do like this FirstOrDefault(x=>x.Id). Here Id is just a representation of a field or property. You can use any property that you want to apply filter condition.
Regards,
Pasang
Sujeet RamanPosted Jan 5, 2023, 8:52 AM
public string EmployeeType =>
ContentTypes.GetemployeeType(employeelist?._manager, employeelist.FirstOrDefault()?.File.address?? string.Empty);
here employeelist?._manager, also make the list to single object first like by using First or FirstOrdefault().?
Pasang TamangPosted Jan 5, 2023, 8:45 AM
Hi,
Looking into your code, your problem is in employeelist?.File.address. employeelist is IReadOnlyList which will represents read only collections. You should make the list to single object first like by using First or FirstOrdefault().
Reagrds,
Pasang