C# 使用windows phone 7初始化,是否正确?

C# 使用windows phone 7初始化,是否正确?,c#,windows-phone-7,C#,Windows Phone 7,嗨,我要创建一个名为“day”的对象,它存储当天所有用户的移动(longditude,latitude)。。 把这一天想象成一个会议,它将被列在一个列表框中,我只想要一个名字,但要多个longditudes&lations 现在我声明这些数组没有popper大小,这对我来说是正确的吗??(直到创建了一个实例) 公共课日:INotifyPropertyChanged { 私有字符串名称; /// ///示例ViewModel属性;此属性在视图中用于使用绑定显示其值。 /// /// [数据成

嗨,我要创建一个名为“day”的对象,它存储当天所有用户的移动(longditude,latitude)。。 把这一天想象成一个会议,它将被列在一个列表框中,我只想要一个名字,但要多个longditudes&lations

现在我声明这些数组没有popper大小,这对我来说是正确的吗??(直到创建了一个实例)

公共课日:INotifyPropertyChanged
{
私有字符串名称;
/// 
///示例ViewModel属性;此属性在视图中用于使用绑定显示其值。
/// 
/// 
[数据成员]
公共字符串名
{
得到
{
返回名称;
}
设置
{
如果(值!=名称)
{
名称=值;
NotifyPropertyChanged(“名称”);
}
}
}
私有字符串[]经度;
[数据成员]
公共字符串[]经度
{
得到
{
返回经度;
}
设置
{
如果(值!=经度)
{
经度=值;
NotifyPropertyChanged(“经度”);
}
}
}
私有字符串[]纬度;
[数据成员]
公共字符串[]纬度
{
得到
{
返回纬度;
}
设置
{
如果(值!=纬度)
{
纬度=值;
NotifyPropertyChanged(“纬度”);
}
}
}
//保存到隔离存储(dat文件)
公共作废保存()
{
ObservableCollection currentDay=IsolatedStorage.Load(App.daysFileName);
当前日期。添加(此);
IsolatedStorage.Save(App.daysFileName,currentDay);
}

是的,这是正确的。与编译时相比,.NET中的数组是在运行时创建和调整大小的。

使用列表是否有任何问题。您是否希望获得更好的性能?使用列表代码更易于维护,更具可读性,当然也更少bug。@Splendor:+1我同意列表可能是一个更好的解决方案,因为它动态调整自身大小。@Zach Johnson,+1作为您的答案。请查看我之前的评论。谢谢各位,我刚刚将字符串保存到独立存储中,但这是一个不同的应用程序,我需要在一个对象中保存未知数量的经度和纬度。我将在一个while循环中添加到它。@Ryan:听起来像列表的一个很好的用法,因为您可以调用Add(),它会根据需要自动调整其内部数组的大小。我将它们作为列表存储在独立的存储中:P public static void Save(string name,T objectToSave)。整晚都没睡,没有想清楚lol。
    public class day : INotifyPropertyChanged
{
    private string name;
    /// <summary>
    /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
    /// </summary>
    /// <returns></returns>
    [DataMember]
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            if (value != name)
            {
                name = value;
                NotifyPropertyChanged("Name");
            }
        }
    }
    private string[] longitude;
    [DataMember]
    public string[] Longitude
    {
        get
        {
            return longitude;
        }
        set
        {
            if (value != longitude)
            {
                longitude = value;
                NotifyPropertyChanged("Longitude");
            }
        }
    }


    private string[] latitude;
    [DataMember]
    public string[] Latitude
    {
        get
        {
            return latitude;
        }
        set
        {
            if (value != latitude)
            {
                latitude = value;
                NotifyPropertyChanged("Latitude");
            }
        }
    }


    // Save to isoldated storage (dat file) 
    public void Save()
    {
        ObservableCollection<day> currentDay = IsolatedStorage.Load<ObservableCollection<day>>(App.daysFileName);
        currentDay.Add(this);
        IsolatedStorage.Save<ObservableCollection<day>>(App.daysFileName, currentDay);
    }