I'm very new to C# so please bear with me...
I'm implementing a partial class, and would like to add two properties like so:
public partial class SomeModel
{
public bool IsSomething { get; set; }
public List<string> SomeList { get; set; }
... Additional methods using the above data members ...
}
I would like to initialize both data members: IsSomething
to True
and SomeList
to new List<string>()
. Normally I would do it in a constructor, however because it's a partial class I don't want to touch the constructor (should I?).
What's the best way to achieve this?
Thanks
PS I'm working in ASP.NET MVC, adding functionality to a a certain model, hence the partial class.
You can't have two constructors in two parts of a partial class. However, you can use partial methods to accomplish something like it:
If no parts of a partial class defines the partial method, all calls to it would be omitted.
For user of version 6.0 of C#, it's possible to initialize the properties like this :