Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 界面中的列表_C#_Xamarin.forms - Fatal编程技术网

C# 界面中的列表

C# 界面中的列表,c#,xamarin.forms,C#,Xamarin.forms,我有一个接口,在该接口中,我正在设置一个列表并稍后尝试填充该列表,但是在LoadSet()方法中,我得到了null异常 public interface ISettings { List<CustomSetting> CustomSettings { get; set; } } public class SettingsService : ISettings { CameraResolution cameraResolution = new CameraR

我有一个接口,在该接口中,我正在设置一个列表并稍后尝试填充该列表,但是在
LoadSet()
方法中,我得到了null异常

public interface ISettings
{
    List<CustomSetting> CustomSettings { get; set; }
}

public class SettingsService : ISettings
{
    
    CameraResolution cameraResolution = new CameraResolution();
    public string Name { get; set; }

    public List<CustomSetting> CustomSettings { get; set; }

    public SettingsService()
    {
        Name = customSettings.Name;
       CustomSettings = new List<CustomSetting>();
        LoadSet();
     
    }

    public void LoadSet()
    {
        var detail = new CustomSetting
        {
                Name = cameraResolution.Name,
                Value = cameraResolution.Value,
       };
        CustomSettings.Add(detail);
        
    }
}
公共接口设置
{
列出自定义设置{get;set;}
}
公共类设置服务:ISettings
{
CameraResolution CameraResolution=新CameraResolution();
公共字符串名称{get;set;}
公共列表自定义设置{get;set;}
公共设置服务()
{
Name=customSettings.Name;
CustomSettings=新列表();
LoadSet();
}
公共void加载集()
{
var detail=新的自定义设置
{
Name=cameraResolution.Name,
Value=cameraResolution.Value,
};
自定义设置。添加(详细信息);
}
}

您是如何使用此服务的,请同时添加该代码,同时尝试此
公共列表自定义设置{get;set;}=new List()绑定上下文=新设置服务();和填充公共列表加载(){items=new List(){new CameraResolution{Name=“low”},new CameraResolution{Name=“high”},};返回项;}我尝试了你的建议,但没有任何结果。我测试了上述代码,它在我的项目中运行良好。你可以发布完整的代码来重现这个问题,这样我就可以在我这边检查它。如果你得到一个null ref异常,请逐步检查代码,直到找到原因。构造函数中只有4行代码,应该很容易跟踪。