What is the C# equivalent of NSMutableArray and NSArray?
Does C# have a mutable and non-mutable? I noticed that string appears to be mutable by default.
As a bonus, how do I quickly populate the array in C#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That would be
ArrayListandobject[]respectively, if you take the weak typing nature ofNSMutableArrayandNSArrayinto account.Arrays and lists in C# (at least for .NET 2.0 and above) can also be strongly-typed, so depending on what kind of object you’re storing you can specify that type. For example if you only have
NSStringobjects in anNSMutableArrayin your Objective-C code, you’d useList<string>, and if you have them in anNSArray, you’d usestring[]with a fixed size instead.To quickly initialize and populate a list or an array in C#, you can use what’s known as a collection initializer:
stringin C# is immutable, just likeNSStringin the Foundation framework. Every time you assign a new string to a variable, you simply point or refer the variable to a different object.