المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Collection properties should be readonly.



C# Programming
08-24-2009, 04:01 PM
Hi,
According to FXCop, i must have arraylist property as read only (not setter).

i tried below method as was mentioned in msdn site(http://msdn.microsoft.com/en-us/library/ms182327(VS.80).aspx):

public ArrayList SomeStrings
{
get { return strings; }
// Violates the rule.
// set { strings = value; }
}


ArrayList newCollection = new ArrayList();
WritableCollection collection = new WritableCollection();
collection.SomeStrings = newCollection;
collection.SomeStrings.Clear();
collection.SomeStrings.AddRange(newCollection);

But at the point marked bold italic, i get error saying that the property is readonly.

I'm really stuck here, can anyone plz give m solution?
I need to set data to the arraylist, but its not FXCop compliant.