How can I translate this Java code:
private List<MPoint> classes = new ArrayList<MPoint>(); // MPoint is my own class
to C#? And what does final keyword mean in Java? What analogue there is to it in C#? I am newbie in C# and Java and I need help :)
private IList<MPoint> classes = new List<MPoint>();
IList<T>
is an interface implemented by the generic collection class List<T>
.
final
has different meanings in Java depending on its context:
final
on a class or method is like sealed
in C#final
on a variable is like readonly
in C#.Equivalent of final
in C# is discussed in detail here.
private IList<MPoint> classes = new List<MPoint>();
The Java List
interface is analogous to the .NET IList<T>
interface.
The ArrayList
concrete type is is analogous to the .NET List<T>
type.
final
is a bit more complicated. In this case (field declaration + initializer), the closest would be readonly
. On the other hand, as of the current version, there's no way to mark a local variable as final
in C#. (Off-topic, final
in the context of compile-time constants = const
. In the context of "cannot override / inherit further" = sealed
).
EDIT: To answer your question about what "final" means, it is normally used to indicate a kind of immutability - that something cannot be further modified or overridden. What sort of mutability is actually prevented with that modifier and its C# analogues depends on context and is hard to describe without going into specifics.
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