"Force" initalitzing with 'null' or other value


I would like to know if it is possible to activate an option that the developer is "forced" to initalize a variable/object with a value or 'null'.

Also just a hint given by Resharper would be usefull.

So, for example, the question is if its possible to enable the option to show a tooltip by Resharper when initializing like this:

private SqlCommand command;

instead of

private SqlCommand command = null;

Please let me know if you need more information.

Comment actions Permalink

Hello James,

As far as I remember, Resharper Action 'Initialize variable' always creates a hotspot with null by default, however you may start typing right away to change the null to any other value.
Sorry if I didn't understand the question well - if so, could you please provide me a small example of what you're talking about and would like/not like ReSharper to do?

Thanks in advance.

Comment actions Permalink

Thank you for your reply; yes - I think your answer could help so solve this problem. Unfortunately, I did not find the specific option  'Initialize variable' you mentioned - could you please tell me where I can activate this option?

Comment actions Permalink

Hi James,

The case is really simple. I've attached 2 screens here:
- First (426) is showing the context action 'Initialize variable' on non-initialized one
- Second (427) is showing the result of this action - red hotspot with defailt value (which is 0 for int type), however you may start typing straigh away to replace the default value with the needed one.

ReSharper is acting the same for other variable types.
Hope this helps.

Comment actions Permalink

Great - Thank you again for your help! :)



Please sign in to leave a comment.