A naming convention that works with IntelliSense

I started calling my current class variables as follows:

    Car car;

The reason is that I think the car is a great description for a variable, and I don't need to add any additional information.

This worked great for me and I was very pleased, but there is one problem that drives me crazy. This is due to IntelliSense if I want to make a type that it can use for a private variable, and vice versa.

I saw people:

    Car myCar;

I'm not crazy, but it will probably work.

Any ideas on how to make this better?

I would like to add that this mainly applies to instances of classes created inside methods.

+3
source share
7 answers

, .

. , , , - .

.NET:

  • _privateVariable ( Microsoft , Linq2Sql)

  • m_privateVariable ( Microsoft, , TypedDatasets , .)

  • PascalCaseAndNoExtras
  • varacibles loacl camelcaseAndNoExtras

-, , . , . .

. , , m_CarToRent m_Car .

+3

this this.car. intellisense. , , _car.

+2

, , _Car -.

+1

:

public class Driver
{
 private Car _car;
 public Car Car { get { return _car; } }
 public Driver(Car car)
 {
  _car = car;
 }
}

_ , , , "m_", "_" "", "" .

Resharper http://www.jetbrains.com/resharper/, .

, 'this' .

+1

- . , m, e, v, i, p (MemberVariable, Event, Volatile, Index/Iterator, Pointer) .., , intellisense, . , - ( ). , .

-, . Car car , , : Car Car {get;set;}, , . , , , , (, ) .

, , ( / , ):

  • : Vehicle car;.
  • () - () Vehicle licensedVehicle. , - , ,

, . , , ( "" ) :

Vehicle.Type. : (, , , ). Car, Bus, Truck. ( = ) "" (, , ). , Vehicle.Type Bus.Type, . "" , (). Vehicle.VehicleType Bus.BusType , .

( , , , , - , , , )

+1

"" () , .

Car currentCar = new Car();

foreach( var currentCar in CarList ) {
   currentCar.Xxxx();
}

, , .

+1

VS, . Car - Accord, Celica Mini myCar, car1 ..: -)

0

Source: https://habr.com/ru/post/1727031/


All Articles