Search code examples
.netcode-standards

.Net Full qualified name for variable type


Where I work, I often see code like that :

public void Test(Models.User.UserInfo userInfo, Models.User.UserParameter param)
   { ... }

Personally, I prefer to see something like that :

public void Test(UserInfo userInfo, UserParameter param) { ... }

And have an import at top.

What you think about this ? What the best practices ? What the pro and cons of both ? How could I convince my teammates ?

I find second option to be more clear.


Solution

  • Definitely use the using directive, IMO. Typically this is just code that has been autogenerated by Visual Studio. I haven't seen anyone deliberately write code like this manually. IMO it's worth making sure that all code that humans will read looks like humans wrote it - so I'd add the using directive and reduce the names here. It makes it much easier to read - particularly when the namespaces are long.