diff --git a/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md b/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md index 2bd31b7722..c85725b9cf 100644 --- a/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md +++ b/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md @@ -19,19 +19,22 @@ ms.assetid: 7b6c5e00-3771-46b4-9142-5a80d5864a5e - The designer generates more efficient code. - > [!NOTE] - > Either apply the or provide `Reset`*PropertyName* and `ShouldSerialize`*PropertyName* methods. Do not use both. +> [!NOTE] +> Either apply the or provide `Reset`*PropertyName* and `ShouldSerialize`*PropertyName* methods. Do not use both. + +When declaring a `ShouldSerialize` or `Reset` method, use the `private` access modifier. These methods are usually invoked by the designer and not by user code. The `Reset`*PropertyName* method sets a property to its default value, as shown in the following code fragment. ```vb -Public Sub ResetMyFont() +Private Sub ResetMyFont() MyFont = Nothing End Sub ``` ```csharp -public void ResetMyFont() { +private void ResetMyFont() +{ MyFont = null; } ``` @@ -44,15 +47,16 @@ public void ResetMyFont() { ```vb 'Returns true if the font has changed; otherwise, returns false. ' The designer writes code to the form only if true is returned. -Public Function ShouldSerializeMyFont() As Boolean - Return Not (thefont Is Nothing) +Private Function ShouldSerializeMyFont() As Boolean + Return thefont IsNot Nothing End Function ``` ```csharp // Returns true if the font has changed; otherwise, returns false. // The designer writes code to the form only if true is returned. -public bool ShouldSerializeMyFont() { +private bool ShouldSerializeMyFont() +{ return thefont != null; } ``` @@ -94,11 +98,11 @@ Public Class MyControl End Set End Property - Public Function ShouldSerializeMyFont() As Boolean - Return Not (thefont Is Nothing) + Private Function ShouldSerializeMyFont() As Boolean + Return thefont IsNot Nothing End Function - Public Sub ResetMyFont() + Private Sub ResetMyFont() MyFont = Nothing End Sub End Class @@ -128,11 +132,13 @@ public class MyControl : Control { } } - public bool ShouldSerializeMyFont() { + private bool ShouldSerializeMyFont() + { return thefont != null; } - public void ResetMyFont() { + private void ResetMyFont() + { MyFont = null; } }