在类的每个类变量中使用“this”关键字是不错的做法? [关闭]

问题描述 投票:0回答:1

我只是想知道在课堂上使用这个关键字与类变量是好习惯还是坏?

如果我使用它会减少或增加应用程序的运行时间/编译时间吗?如下: -

this.FirsName = cust.name;
this.LastName = cust.Lname;
this.Age = cust.age;
this.DOB = cust.dob;

等等超过1000行代码......

c# .net this
1个回答
4
投票

它不会影响您的编译时间或运行时间。这也不是一个好习惯。

使用this关键字的原因是将类别道具分离到特定部分内的另一个属性。

如果您谈论代码约定和样式,只需采用Microsofts:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions

你应该阅读Microsoft文档:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/this

© www.soinside.com 2019 - 2024. All rights reserved.