Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming terms - field, member, properties (C#)

I was trying to find meaning of this terms but especially due to language barrier I was not able to understand what they are used for. I assume that "field" is variable (object too?) in the class while "property" is just an object that returns specific value and cannot contain methods etc. By "member" I understand any object that is declared on the class level. But these are just my assumptions based on commented code samples where some careful programmers used "property region" etc. I would really appreciate if someone could explain it to me.

like image 219
Petr Avatar asked Apr 27 '10 09:04

Petr


People also ask

What are fields and properties in C?

Fields are ordinary member variables or member instances of a class. Properties are an abstraction to get and set their values. Properties are also called accessors because they offer a way to change and retrieve a field if you expose a field in the class as private.

What is a property and member?

Both properties and methods are members of an object. A property describes some aspect of the object while a method accesses or uses the owning object.

What are properties C?

Properties are the special type of class members that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors.

What are members in programming?

In object-oriented programming, a member variable (sometimes called a member field) is a variable that is associated with a specific object, and accessible for all its methods (member functions).


1 Answers

In C# :

fields : These are variables declared at the class level.

public class SomeClass {     private int someInteger; // This is a field     public double someDouble; // This is another field     protected StringBuidler stringBuidler; // Still another field } 

properties : Often used as accessors to a private field of a class, they can provide get and set methods that wrap some logic around the field manipulation.

public class SomeClass {     private StringBuilder stringBuilder;      // Property declaration     public StringBuilder StringBuilder     {         get          {              if(this.stringBuilder == null)                 this.stringBuilder = new StringBuidler();              return this.stringBuilder;         }         set         {             if(this.stringBuilder == null)                 this.stringbuilder = value;         }     } } 

members : Includes fields, properties, methods, events of a class.

like image 159
Thibault Falise Avatar answered Sep 18 '22 15:09

Thibault Falise