Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# field vs property

public class MyClass
{
    // this is a field.  It is private to your class and stores the actual data.
    private string _myField;

    // this is a property. When accessed it uses the underlying field,
    // but only exposes the contract, which will not be affected by the underlying field
    public string MyProperty
    {
        get
        {
            return _myField;
        }
        set
        {
            _myField = value;
        }
    }

    // This is an AutoProperty (C# 3.0 and higher) - which is a shorthand syntax
    // used to generate a private field for you
    public int AnotherProperty { get; set; } 
}
Comment

properties vs field c#

//Encapsulation
//So you can't change the values accidentally by setting it private, you can only read the value(get) and change it(set) through a gatekeeper(properties).
Comment

PREVIOUS NEXT
Code Example
Csharp :: remove last character from stringbuilder c# 
Csharp :: blender how to switch cameras 
Csharp :: c# open config file by path 
Csharp :: binary search tree c# stackoverflow 
Csharp :: membership get user id 
Csharp :: dotween do rotate on one axis 
Csharp :: lexicographically sorted 
Csharp :: c# change chart legend font size 
Csharp :: unity timer 
Csharp :: c# run foreach loop x times 
Csharp :: Program to find GCD or HCF of two numbers c# 
Csharp :: how to add a round image unity 
Csharp :: C# program applies bonus points 
Csharp :: how to count specific controls in a container c# 
Csharp :: Cursor Invisibility 
Csharp :: client = matrice[indexselectedclient] as String[]; 
Csharp :: AutoFixture ignore property 
Csharp :: C# is folder 
Csharp :: add integer to string c# 
Csharp :: how to if i enter 1 go to this program C# 
Csharp :: C# verify "no other" call xunit 
Csharp :: convert array to datatable c# 
Csharp :: how to get image from resource folder in c# 
Csharp :: c# list with only unique items 
Csharp :: unity c# flip sprite 
Csharp :: what is c# used for 
Csharp :: what does - in f#? 
Csharp :: read administrator account remote machine C# 
Html :: You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0). 
Html :: degree symbol html 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =