Skip to content

Commit 2699b65

Browse files
committed
Adding an example of a useless setter.
1 parent e7d64c0 commit 2699b65

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

source/code/projects/Properties_errors/Properties_errors/Derived.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public string Attr1
3030
}
3131
3232
*/
33+
34+
// A similar issue is to have a setter that does nothing:
35+
36+
public string Attr2 {get{return attr1;} set{}}
37+
38+
public string GetAttr2(){
39+
return attr1;
40+
}
41+
42+
3343
// Misconception #2
3444
public void Test(string argP)
3545
{

source/code/projects/Properties_errors/Properties_errors/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ static void Main()
99

1010
test1.Test(null);
1111
test1.Test();
12+
13+
test1.Attr2 = "This is the parameter.";
14+
Console.WriteLine(test1.GetAttr2());
1215

1316
try
1417
{

0 commit comments

Comments
 (0)