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 :: gameobject in unity c# 
Csharp :: redirect to another controller page in asp.net core 
Csharp :: how to remove vowels from a sttring using regex c# 
Csharp :: OnMousedown unity ui 
Csharp :: c# move files from one folder to another 
Csharp :: c# remove items from one list that are in another 
Csharp :: get folder path winforms 
Csharp :: how to get integer value from textbox in c# 
Csharp :: c# update control from another thread 
Csharp :: make http request c# 
Csharp :: console.writeline in c# 
Csharp :: unity change cursor texture 
Csharp :: Minimize window to system tray c# 
Csharp :: c# Get all class by namespace 
Csharp :: swap two numbers c# 
Csharp :: set request timeout c# 
Csharp :: c# add to array 
Csharp :: c# get directory name from filename 
Csharp :: unity call function from another script 
Csharp :: c# dictionary values to list 
Csharp :: c# parse string to xml 
Csharp :: webclient timeout 
Csharp :: datetime check null c# 
Csharp :: get user startup folder path C# 
Csharp :: ffmpeg add audio to video at specific time 
Csharp :: find how many digits a number has 
Csharp :: get percentage c# 
Csharp :: c# calculate sum of list 
Csharp :: c# add element to array 
Csharp :: while c# 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =