Relative Content

Tag Archive for initialization

Make Return Type an Interface – Problem with Initialization

I would like to make the return type of my method an interface rather than a class for similar reasons stated in c# List or IList, however I am having trouble figuring out how to initialize the interface to return it. I cannot use new IA() and (IA) new A() does not work as I cannot cast the result to B.

Initialize in Field, Constructor, or Argument

If I know what a field will be initialized to, should I initialize it in the field, constructor, or receive it as a parameter? I am asking about best practices. All three options effectively provide the same result. I am not considering what is happening behind the scenes, because I think it would be insignificant.

Initialize in Field, Constructor, or Argument

If I know what a field will be initialized to, should I initialize it in the field, constructor, or receive it as a parameter? I am asking about best practices. All three options effectively provide the same result. I am not considering what is happening behind the scenes, because I think it would be insignificant.