I have seen some people creating properties in C# really fast, but how did they do it?
What shortcuts are available in Visual Studio (currently using Visual Stu
Type "propfull". It is much better to use, and it will generate the property and private variable.
Type "propfull" and then TAB twice.
Type P + Tab + Tab.
Change the datatype, press TAB, change the property name, and press End + Enter.
In C#:
private string studentName;
At the end of line after semicolon(;) Just Press
Ctrl + R + E
It will show a popup window like this: On click of Apply or pressing of ENTER it will generate the following code of property:
public string StudentName
{
get
{
return studentName;
}
set
{
studentName = value;
}
}
In VB:
Private _studentName As String
At the end of line (after String) Press, Make sure you place _(underscore) at the start because it will add number at the end of property:
Ctrl + R + E
The same window will appear:
On click of Apply or pressing of ENTER it will generate the following code of property with number at the end like this:
Public Property StudentName As String
Get
Return _studentName
End Get
Set(value As String)
_studentName = value
End Set
End Property
With number properties are like this:
Private studentName As String
Public Property StudentName1 As String
Get
Return studentName
End Get
Set(value As String)
studentName = value
End Set
End Property
Start from:
private int myVar;
When you select "myVar" and right click then select "Refactor" and select "Encapsulate Field".
It will automatically create:
{
get { return myVar; }
set { myVar = value; }
}
Or you can shortcut it by pressing Ctrl + R + E.
Place cursor inside your field private int _i;
and then Edit menu or RMB - Refactor - Encapsulate Field... (CtrlR, CtrlE) to create the standard property accessors.
After typing "prop" + Tab + Tab as suggested by Amra,
you can immediately type the property's type (which will replace the default int
), type another tab and type the property name (which will replace the default MyProperty). Finish by pressing Enter.