Hi. I'm trying to learn c# using some online tutorials. At one point, it was teaching me that objects are defined by attributes (data) and behaviors. Example of an Object could be a person with eye, color, and height as attributes.
Than later on, I'm learning about properties. The examples give height and width.
So than i'm thinking, hmmm height is giving as an example as an attribute when trying to explain objects and than height is also giving as an example when trying to show code examples for properties.
Than I start getting confused thinking so are attributes the same as properties? Why am I getting confused here?
in oop entity attributes maps to class data fields...
if you have a person class you can have a data field to hold a height value of a person...
Data fields are private in general... and properties are special methods to give access to these private class members...
Sample:
public class Person
{
private int height; // this is a data field
public int Height // this is a property
{
get { return this.height; } //getter method of the property. returns the backing data field's value
set { this.height = value; } //setter method of the property. sets the backing data field's value
}
}
Properties can have only a get or set... The we call properties read only or write only properties according the methods they have...
public String test { get; set; } syntax new in c# 3.5... In this syntax backing private data field and property methods generated by compiler automatically
Generated code looks like this..
private String _test;
public String test
{
get { return this._test; }
set { this._test = value; }
}
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.