<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C# kódok &#187; tulajdonságok</title>
	<atom:link href="http://users.atw.hu/csharpkodok/" rel="self" type="application/rss+xml" />
	<link>http://users.atw.hu/csharpkodok</link>
	<description>Csharp kódok gyüjteménye</description>
	<lastBuildDate>Fri, 07 Aug 2009 11:44:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Objektum Orientált Programozás (kód elmélet)</title>
		<link>http://users.atw.hu/csharpkodok/?p=37</link>
		<comments>http://users.atw.hu/csharpkodok/?p=37#comments</comments>
		<pubDate>Thu, 16 Jul 2009 07:31:47 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[elmélet]]></category>
		<category><![CDATA[kód]]></category>
		<category><![CDATA[Objektum orientál programozás]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[set get]]></category>
		<category><![CDATA[tulajdonságok]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=37</guid>
		<description><![CDATA[Objektum Orientált Programozás (kód elmélet):


using System;
&#160;
namespace Program
{
    sealed class Radio
    {
        public void Power(bool turnOn)
        {
            Console.WriteLine(&#34;Radio on: {0}&#34;, turnOn);
     [...]]]></description>
			<content:encoded><![CDATA[<p>Objektum Orientált Programozás (kód elmélet):<br />
<span id="more-37"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    sealed class Radio
    {
        public void Power(bool turnOn)
        {
            Console.WriteLine(&quot;Radio on: {0}&quot;, turnOn);
        }
    }
&nbsp;
    class Car
    {
        // az autónak van egy rádiója
        private Radio myRadio = new Radio();
&nbsp;
        public void TurnOnRadio(bool onOff)
        {
            //Hívás továbbítása a belső objektumnak
            myRadio.Power(onOff);
        }
    }
&nbsp;
    class MainClass
    {
        public static void Main()
        {
            //A hívás belső továbbítása a Radio osztáklynak
            Car viper = new Car();
            viper.TurnOnRadio(true);
&nbsp;
            Console.ReadKey();
        }
    }
}</pre></div></div>

<p>A Rádiót külön osztályba soroljuk, mert semmi köze sincs az autóhoz, csak annyi, hogy benne van&#8230;</p>
<p>Most írunk egy olyan programot, ami lemodellezi egy dolgos dolgozó munkáját:<br />
Először hozzunk létre egy új alkalmazást EmployeeApp néven, és szúrjunk be egy új osztályt a Project -> Add class menüelemmel.<br />
Módosítsuk az Employee osztályt a következő mezőkkel, metódusokkal és konstruktorokkal:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
&nbsp;
namespace EmployeeApp
{
    class Employee
    {
        //mezőadatok
        private string empName;
        private int empID;
        private float currPay;
&nbsp;
&nbsp;
        //lekérdező get metódus
        public string GetName()
        {
            return empName;
        }
&nbsp;
        //Módosító set metódus
        public void SetName(string name)
        {
            empName = name;
        }
&nbsp;
        //Konstruktorok
        public Employee() { }
        public Employee(string name, int id, float pay)
        {
            empName = name;
            empID = id;
            currPay = pay;
        }
&nbsp;
        public void GiveBonus(float amount)
        {
            currPay += amount;
        }
        public void DisplayStats()
        {
            Console.WriteLine(&quot;Name: {0}&quot;,empName);
            Console.WriteLine(&quot;ID: {0}&quot;, empID);
            Console.WriteLine(&quot;Pay: {0}&quot;, currPay);
        }
&nbsp;
    }
}</pre></div></div>

<p>Main() rész:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
&nbsp;
namespace EmployeeApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee emp = new Employee(&quot;Marvin&quot;, 436, 3000);
            emp.GiveBonus(1000);
            emp.DisplayStats();
&nbsp;
            //munka az objektum nevével a get/set módosítók segítségével
            emp.SetName(&quot;Marv&quot;);
            Console.WriteLine(&quot;Employee is named: {0}&quot;, emp.GetName());
&nbsp;
            Console.ReadKey();
        }
    }
}</pre></div></div>

<p><a href="http://www.csharpkodok.atw.hu/feltoltesek/EmployeeApp.zip">A projekt letöltése</a></p>
<p>Egységbe zárás propertykkel:  (property, tulajdonságok, set, get)</p>
<p>Main rész:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
&nbsp;
namespace EmployeeApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee emp = new Employee(&quot;Marvin&quot;, 436, 3000);
            emp.GiveBonus(1000);
            emp.DisplayStats();
&nbsp;
            //a Name tulajdonságok beolvasása és beállítása
            emp.Name = &quot;Marv&quot;;
            Console.WriteLine(&quot;Employee is named: {0}&quot;, emp.Name);
&nbsp;
            Console.ReadKey();
        }
    }
}</pre></div></div>

<p>A hozzáadott osztály:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
&nbsp;
namespace EmployeeApp
{
    class Employee
    {
        //mezőadatok
        private string empName;
        private int empID;
        private float currPay;
&nbsp;
&nbsp;
        //tulajdonságok
        public string Name
        {
            get { return empName; }
            set { empName = value; }
        }
&nbsp;
        public float pay
        {
            get { return currPay; }
            set { currPay = value; }
        }
&nbsp;
        //Konstruktorok
        public Employee() { }
        public Employee(string name, int id, float pay)
        {
            empName = name;
            empID = id;
            currPay = pay;
        }
&nbsp;
        public void GiveBonus(float amount)
        {
            currPay += amount;
        }
        public void DisplayStats()
        {
            Console.WriteLine(&quot;Name: {0}&quot;,empName);
            Console.WriteLine(&quot;ID: {0}&quot;, empID);
            Console.WriteLine(&quot;Pay: {0}&quot;, currPay);
        }
&nbsp;
    }
}</pre></div></div>

<p>Statikus tulajdonságok, statikus probertyk:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class MainClass
    {
        public static void Main()
        {
            WebSite.WebName = &quot;www.csharpkodok.atw.hu&quot;;
            Console.WriteLine(WebSite.WebName);
&nbsp;
            Console.ReadKey();
        }
    }
&nbsp;
    class WebSite
    {
        //statikus tulajdonsághoz a mezőnek is statikusnak kell lennie...
        private static string WebsiteName;
        public static string WebName
        {
            get { return WebsiteName; }
            set { WebsiteName = value; }
        }
    }
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=37</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
