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#?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A.
That would be ArrayList
and object[]
respectively, if you take the weak typing nature of NSMutableArray
and NSArray
into 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 NSString
objects in an NSMutableArray
in your Objective-C code, you'd use List<string>
, and if you have them in an NSArray
, you'd use string[]
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:
List<string> list = new List<string> { "foo", "bar", "baz" };
string[] array = { "foo", "bar", "baz" }; // Shortcut syntax for arrays
string
in C# is immutable, just like NSString
in the Foundation framework. Every time you assign a new string to a variable, you simply point or refer the variable to a different object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With