Skip to main content
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

Prefixing either parameters or local variables with an underscore is not very idiomatic in C#, it is not very easy to read and not often used (although it is legal, so you are free to so if you wish).

The best name for the parameter and the variable is a descriptive name. You need to think why you are changing the type, what is the reason for the cast. Then you should be able to come up with 2 different names. E.g. is you passed a "person" and converted it to a "customer" then you could use person and / or customer in the variable names perhaps.

If you really can't think of 2 different names then I would use "as" in the name (there was a question on this site a few days ago about thisthere was a question on this site a few days ago about this). E.g. you would use "myParaAsDerived" for the local variable.

If at all possible I would not use this, I would think hard about the problem you are solving and what meaningful names could be used, but if all else fails this is fairly readable.

Prefixing either parameters or local variables with an underscore is not very idiomatic in C#, it is not very easy to read and not often used (although it is legal, so you are free to so if you wish).

The best name for the parameter and the variable is a descriptive name. You need to think why you are changing the type, what is the reason for the cast. Then you should be able to come up with 2 different names. E.g. is you passed a "person" and converted it to a "customer" then you could use person and / or customer in the variable names perhaps.

If you really can't think of 2 different names then I would use "as" in the name (there was a question on this site a few days ago about this). E.g. you would use "myParaAsDerived" for the local variable.

If at all possible I would not use this, I would think hard about the problem you are solving and what meaningful names could be used, but if all else fails this is fairly readable.

Prefixing either parameters or local variables with an underscore is not very idiomatic in C#, it is not very easy to read and not often used (although it is legal, so you are free to so if you wish).

The best name for the parameter and the variable is a descriptive name. You need to think why you are changing the type, what is the reason for the cast. Then you should be able to come up with 2 different names. E.g. is you passed a "person" and converted it to a "customer" then you could use person and / or customer in the variable names perhaps.

If you really can't think of 2 different names then I would use "as" in the name (there was a question on this site a few days ago about this). E.g. you would use "myParaAsDerived" for the local variable.

If at all possible I would not use this, I would think hard about the problem you are solving and what meaningful names could be used, but if all else fails this is fairly readable.

Source Link
Steve
  • 5.3k
  • 1
  • 24
  • 27

Prefixing either parameters or local variables with an underscore is not very idiomatic in C#, it is not very easy to read and not often used (although it is legal, so you are free to so if you wish).

The best name for the parameter and the variable is a descriptive name. You need to think why you are changing the type, what is the reason for the cast. Then you should be able to come up with 2 different names. E.g. is you passed a "person" and converted it to a "customer" then you could use person and / or customer in the variable names perhaps.

If you really can't think of 2 different names then I would use "as" in the name (there was a question on this site a few days ago about this). E.g. you would use "myParaAsDerived" for the local variable.

If at all possible I would not use this, I would think hard about the problem you are solving and what meaningful names could be used, but if all else fails this is fairly readable.