<?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; kód</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>Egyedi kivételkezelés 1.</title>
		<link>http://users.atw.hu/csharpkodok/?p=113</link>
		<comments>http://users.atw.hu/csharpkodok/?p=113#comments</comments>
		<pubDate>Sun, 02 Aug 2009 18:15:23 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=113</guid>
		<description><![CDATA[Ez a forráskód úgy van megoldva, hogy több .cs fájl foglal magába. Project -> Add new Item -> Class
Egyedi kivételkezelés 1.

program.cs:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
&#160;
namespace CustomException
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(&#34;***** Fun with Custom Exceptions *****\n&#34;);
   [...]]]></description>
			<content:encoded><![CDATA[<p>Ez a forráskód úgy van megoldva, hogy több .cs fájl foglal magába. Project -> Add new Item -> Class<br />
Egyedi kivételkezelés 1.<br />
<span id="more-113"></span><br />
program.cs:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
&nbsp;
namespace CustomException
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(&quot;***** Fun with Custom Exceptions *****\n&quot;);
      Car myCar = new Car(&quot;Rusty&quot;, 90);
      try
      {
        // Trip exception.
        myCar.Accelerate(50);
      }
      catch (CarIsDeadException e)
      {
        Console.WriteLine(e.Message);
        Console.WriteLine(e.TimeStamp);
        Console.WriteLine(e.Cause);
      }
      Console.ReadLine();
    }
  }
}</pre></div></div>

<p>cars 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.Text;
&nbsp;
namespace CustomException
{
  public class Car
  {
    #region Member variables &amp; Constructors
    // Constant for maximum speed.
    public const int MaxSpeed = 100;
&nbsp;
    // Internal state data.
    private int currSpeed;
    private string petName;
&nbsp;
    // Is the car still operational?
    private bool carIsDead;
&nbsp;
    // A car has-a radio.
    private Radio theMusicBox = new Radio();
&nbsp;
    // Constructors.
    public Car() {}
    public Car(string name, int currSp)
    {
      currSpeed = currSp;
      petName = name;
    }
    #endregion
&nbsp;
    #region Methods
    public void CrankTunes(bool state)
    {
      // Delegate request to inner object.
      theMusicBox.TurnOn(state);
    }
&nbsp;
    // This time, throw an exception if the user speeds up beyond MaxSpeed.
    public void Accelerate(int delta)
    {
      if (carIsDead)
        Console.WriteLine(&quot;{0} is out of order...&quot;, petName);
      else
      {
        currSpeed += delta;
        if (currSpeed &gt;= MaxSpeed)
        {
          carIsDead = true;
          currSpeed = 0;
&nbsp;
          // We need to call the HelpLink property, thus we need
          // to create a local variable before throwing the Exception object.
          CarIsDeadException ex =
          new CarIsDeadException(string.Format(&quot;{0} has overheated!&quot;, petName),
          &quot;You have a lead foot&quot;, DateTime.Now);
          ex.HelpLink = &quot;http://www.CarsRUs.com&quot;;
          throw ex;
        }
        else
          Console.WriteLine(&quot;=&gt; CurrSpeed = {0}&quot;, currSpeed);
      }
    }
    #endregion
  }
}</pre></div></div>

<p>rádió 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.Text;
&nbsp;
namespace CustomException
{
  public class Radio
  {
    public void TurnOn(bool on)
    {
      if(on)
        Console.WriteLine(&quot;Jamming...&quot;);
      else
        Console.WriteLine(&quot;Quiet time...&quot;);
    }
  }
}
&nbsp;
CarIsDead:
&nbsp;
public class CarIsDeadException : ApplicationException
{
    private string messageDetails;
    private DateTime errorTimeStamp;
    private string causeOfError;
&nbsp;
    public DateTime TimeStamp
    {
         get { return errorTimeStamp; }
         set { errorTimeStamp = value; }
    }
    public string Cause
    {
        get { return causeOfError; }
        set { causeOfError = value; }
    }
&nbsp;
    public CarIsDeadException() { }
    public CarIsDeadException(string message,
    string cause, DateTime time)
    {
       messageDetails = message;
       causeOfError = cause;
      errorTimeStamp = time;
    }
    // Override the Exception.Message property.
    public override string Message
    {
       get
       {
           return string.Format(&quot;Car Error Message: {0}&quot;, messageDetails);
       }
    }
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=113</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kivétel továbbdobása:</title>
		<link>http://users.atw.hu/csharpkodok/?p=108</link>
		<comments>http://users.atw.hu/csharpkodok/?p=108#comments</comments>
		<pubDate>Sun, 02 Aug 2009 18:11:47 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>
		<category><![CDATA[k t]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=108</guid>
		<description><![CDATA[

// Írta CS.K.
using System;
&#160;
namespace Program
{
    static class MainClass
    {
        static void Calc()
        {
            var array = new int[10];
&#160;
       [...]]]></description>
			<content:encoded><![CDATA[<p><span id="more-108"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">// Írta CS.K.
using System;
&nbsp;
namespace Program
{
    static class MainClass
    {
        static void Calc()
        {
            var array = new int[10];
&nbsp;
            try
            {
                for (var i = 0; i &lt; 11; ++i)
                    array[i] = 11;
            }
            catch (IndexOutOfRangeException)
            {
                throw; //itt továbdobja a következő kivétel odóhoz.
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static void Main()
        {
            try
            {
                Calc();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
&nbsp;
            Console.ReadKey();
        }
    }
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=108</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Többszörös kivétel fogadás</title>
		<link>http://users.atw.hu/csharpkodok/?p=106</link>
		<comments>http://users.atw.hu/csharpkodok/?p=106#comments</comments>
		<pubDate>Sun, 02 Aug 2009 18:10:54 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=106</guid>
		<description><![CDATA[Többszörös kivétel fogadás


using System;
&#160;
namespace proba
{
&#160;
    #region abstract radio osztaly
&#160;
    class Radio
    {
        public void TurnRadio(bool on)
        {
            if (on)
   [...]]]></description>
			<content:encoded><![CDATA[<p>Többszörös kivétel fogadás<br />
<span id="more-106"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace proba
{
&nbsp;
    #region abstract radio osztaly
&nbsp;
    class Radio
    {
        public void TurnRadio(bool on)
        {
            if (on)
                Console.WriteLine(&quot;Megy a zene&quot;);
            else
                Console.WriteLine(&quot;nem megy a zene&quot;);
        }
    }
&nbsp;
    #endregion
&nbsp;
&nbsp;
    #region Car osztaly
&nbsp;
    class Car
    {
        int maxspeed;
        int currspeed;
&nbsp;
&nbsp;
        public Car() { }
        public Car(int max, int curr, bool radioOnOff)
        {
            maxspeed = max;
            currspeed = curr;
            var radio = new Radio();
            radio.TurnRadio(radioOnOff);
        }
&nbsp;
        public void Acceleration(int acc)
        {
            if (currspeed &lt; maxspeed)
            {
                currspeed += acc;
                Console.WriteLine(&quot;Acceleration: {0}&quot;, acc);
            }
            else
            {
&nbsp;
                throw new ArgumentOutOfRangeException(&quot;Elerte az auto a maximalis sebesseget! Nem mehetsz gyorsabban!&quot;);
                currspeed = maxspeed;
            }
&nbsp;
        }
&nbsp;
        public void PrintStateInfo()
        {
            Console.WriteLine(&quot;Max speed: {0}&quot;, maxspeed);
            Console.WriteLine(&quot;Current speed: {0}&quot;, currspeed);
&nbsp;
        }
&nbsp;
    }
&nbsp;
    #endregion
&nbsp;
&nbsp;
    #region
&nbsp;
    class MainClass
    {
        public static void Main()
        {
            var rnd = new Random();
            var myCar = new Car(180, 50, true);
&nbsp;
            try
            {
                for (int i = 0; i &lt; 10; i++)
                {
                    myCar.Acceleration(rnd.Next(19, 24));
                    myCar.PrintStateInfo();
                }
            }
            catch (ArgumentOutOfRangeException ex) //Előszor a pontosabb kivételfogást kell létrehoznunk, és csak utána azt ami mindetn megfog
            {                                                                            //ugyanis ha azt előreraknánk akkor semmi esély nem lene lefutni a prontosabb megfogalmazásnak
                Console.WriteLine(ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.ReadKey();
        }
    }
&nbsp;
    #endregion
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=106</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HelpLink</title>
		<link>http://users.atw.hu/csharpkodok/?p=100</link>
		<comments>http://users.atw.hu/csharpkodok/?p=100#comments</comments>
		<pubDate>Sat, 25 Jul 2009 07:45:39 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=100</guid>
		<description><![CDATA[HelpLink tulajdonság:


using System;
&#160;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
           [...]]]></description>
			<content:encoded><![CDATA[<p>HelpLink tulajdonság:<br />
<span id="more-100"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
                Console.WriteLine(&quot;Jamming...&quot;);
            else
                Console.WriteLine(&quot;Quite time...&quot;);
        }
    }
&nbsp;
    class Car
    {
        //max sebesség konstansa
        public const int MaxSpeed = 100;
&nbsp;
        //Belső állapot adatok
        private int currSpeed;
        private string petName;
&nbsp;
        //az autó még mindig működőképes?
        private bool CarIsDead;
&nbsp;
        //Az autónak van egy rádiója
        private Radio theMusicBox = new Radio();
&nbsp;
        //Konstruktorok
        public Car() { }
        public Car(string name, int currSp)
        {
            currSpeed = currSp;
            petName = name;
        }
&nbsp;
        //Rádió be?
        public void CrankTunes(bool state)
        {
            theMusicBox.TurnOn(state);
        }
&nbsp;
        //Kivételt jelez, hogyha a felhasználó a MaxSpeed értéke fölé gyorsítja za autót.
        public void Accelerate(int delta)
        {
            if (CarIsDead)
                Console.WriteLine(&quot;{0} is out of order...&quot;, petName);
            else
            {
                currSpeed += delta;
                if (currSpeed &gt; MaxSpeed)
                {
                    CarIsDead = true;
                    currSpeed = 0;
&nbsp;
                    //A HelpLink tulajdonságot kell hívni, ezért az Exception objektum kiváltása előtt lokállissá kell tenni
                    Exception ex = new Exception(string.Format(&quot;{0} has overheated!&quot;,petName));
                    ex.HelpLink = &quot; http://www.daniel-projects.netne.net&quot;; //kivétel esetén ez azt fogja megjeleníteni a .HelpLink tul.
                    throw ex; //hibát dobunk
                }
                else
                    Console.WriteLine(&quot;=&gt; CurrSpeed = {0}&quot;, currSpeed);
            }
        }
&nbsp;
&nbsp;
    }
&nbsp;
    class MainClass
    {
        public static void Main()
        {
            Console.WriteLine(&quot;*****Simple Exception Example*****&quot;);
            Console.WriteLine(&quot;=&gt; Creating a car and steppong on it!&quot;);
            var myCar = new Car(&quot;David&quot;, 20); //zippy a neve és jelenleg 20-szal megyünk
            myCar.CrankTunes(true); //rádió bekapcsolva
&nbsp;
            try
            {
                for (int i = 0; i &lt; 10; i++)
                    myCar.Accelerate(10); //10-zel nő a sebesség addig, amíg elnem éri a 100-at, utána felrobban
            }
            catch (Exception ex)
            {
                Console.WriteLine(&quot;*** Error! ***&quot;);
&nbsp;
                //**********************&lt;HelpLink&gt;**********************
                Console.WriteLine(&quot;\n\nHelp Link: {0}&quot;, ex.HelpLink);
                //**********************&lt;/HelpLink&gt;********************
&nbsp;
                //************************&lt;StackTrace&gt;******************
                Console.WriteLine(&quot;\n\nStack: {0}\n\n&quot;, ex.StackTrace); //megmutatja a hiba pontos helyét!
                //************************&lt;/StackTace&gt;*****************
&nbsp;
                Console.WriteLine(&quot;Method: {0}&quot;, ex.TargetSite);
                Console.WriteLine(&quot;Class defining member: {0}&quot;,ex.TargetSite.DeclaringType);
                Console.WriteLine(&quot;Member type: {0}&quot;, ex.TargetSite.MemberType);
                Console.WriteLine(&quot;Message: {0}&quot;, ex.Message);
                Console.WriteLine(&quot;Source: {0}&quot;, ex.Source);
            }
&nbsp;
            //A hibát kezeltük, a program FOLYTATÓDIK
            Console.WriteLine(&quot;\n***** Out of Exception logic *****&quot;);
            Console.ReadKey();
        }
    }
&nbsp;
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=100</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StackTrace</title>
		<link>http://users.atw.hu/csharpkodok/?p=98</link>
		<comments>http://users.atw.hu/csharpkodok/?p=98#comments</comments>
		<pubDate>Sat, 25 Jul 2009 07:42:53 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=98</guid>
		<description><![CDATA[StackTrace tulajdonság:


using System;
&#160;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
           [...]]]></description>
			<content:encoded><![CDATA[<p>StackTrace tulajdonság:<br />
<span id="more-98"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
                Console.WriteLine(&quot;Jamming...&quot;);
            else
                Console.WriteLine(&quot;Quite time...&quot;);
        }
    }
&nbsp;
    class Car
    {
        //max sebesség konstansa
        public const int MaxSpeed = 100;
&nbsp;
        //Belső állapot adatok
        private int currSpeed;
        private string petName;
&nbsp;
        //az autó még mindig működőképes?
        private bool CarIsDead;
&nbsp;
        //Az autónak van egy rádiója
        private Radio theMusicBox = new Radio();
&nbsp;
        //Konstruktorok
        public Car() { }
        public Car(string name, int currSp)
        {
            currSpeed = currSp;
            petName = name;
        }
&nbsp;
        //Rádió be?
        public void CrankTunes(bool state)
        {
            theMusicBox.TurnOn(state);
        }
&nbsp;
        //Kivételt jelez, hogyha a felhasználó a MaxSpeed értéke fölé gyorsítja za autót.
        public void Accelerate(int delta)
        {
            if (CarIsDead)
                Console.WriteLine(&quot;{0} is out of order...&quot;, petName);
            else
            {
                currSpeed += delta;
                if (currSpeed &gt; MaxSpeed)
                {
                    CarIsDead = true;
                    currSpeed = 0;
&nbsp;
                    //Kivétel kiváltása a throw segítségével
                    throw new Exception(string.Format(&quot;{0} has overheated!&quot;,petName));
                }
                else
                    Console.WriteLine(&quot;=&gt; CurrSpeed = {0}&quot;, currSpeed);
            }
        }
&nbsp;
&nbsp;
    }
&nbsp;
    class MainClass
    {
        public static void Main()
        {
            Console.WriteLine(&quot;*****Simple Exception Example*****&quot;);
            Console.WriteLine(&quot;=&gt; Creating a car and steppong on it!&quot;);
            var myCar = new Car(&quot;David&quot;, 20); //zippy a neve és jelenleg 20-szal megyünk
            myCar.CrankTunes(true); //rádió bekapcsolva
&nbsp;
            try
            {
                for (int i = 0; i &lt; 10; i++)
                    myCar.Accelerate(10); //10-zel nő a sebesség addig, amíg elnem éri a 100-at, utána felrobban
            }
            catch (Exception ex)
            {
                Console.WriteLine(&quot;*** Error! ***&quot;);
&nbsp;
                //************************&lt;StackTrace&gt;******************
                Console.WriteLine(&quot;\n\nStack: {0}\n\n&quot;, ex.StackTrace); //megmutatja a hiba pontos helyét!
                //************************&lt;/StackTace&gt;*****************
&nbsp;
                Console.WriteLine(&quot;Method: {0}&quot;, ex.TargetSite);
                Console.WriteLine(&quot;Class defining member: {0}&quot;,ex.TargetSite.DeclaringType);
                Console.WriteLine(&quot;Member type: {0}&quot;, ex.TargetSite.MemberType);
                Console.WriteLine(&quot;Message: {0}&quot;, ex.Message);
                Console.WriteLine(&quot;Source: {0}&quot;, ex.Source);
            }
&nbsp;
            //A hibát kezeltük, a program FOLYTATÓDIK
            Console.WriteLine(&quot;\n***** Out of Exception logic *****&quot;);
            Console.ReadKey();
        }
    }
&nbsp;
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=98</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TragetSite</title>
		<link>http://users.atw.hu/csharpkodok/?p=94</link>
		<comments>http://users.atw.hu/csharpkodok/?p=94#comments</comments>
		<pubDate>Sat, 25 Jul 2009 07:41:02 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[elmélet]]></category>
		<category><![CDATA[kód]]></category>
		<category><![CDATA[TragetSite]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=94</guid>
		<description><![CDATA[TragetSite tulajdonságok:


using System;
&#160;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
           [...]]]></description>
			<content:encoded><![CDATA[<p>TragetSite tulajdonságok:<br />
<span id="more-94"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
                Console.WriteLine(&quot;Jamming...&quot;);
            else
                Console.WriteLine(&quot;Quite time...&quot;);
        }
    }
&nbsp;
    class Car
    {
        //max sebesség konstansa
        public const int MaxSpeed = 100;
&nbsp;
        //Belső állapot adatok
        private int currSpeed;
        private string petName;
&nbsp;
        //az autó még mindig működőképes?
        private bool CarIsDead;
&nbsp;
        //Az autónak van egy rádiója
        private Radio theMusicBox = new Radio();
&nbsp;
        //Konstruktorok
        public Car() { }
        public Car(string name, int currSp)
        {
            currSpeed = currSp;
            petName = name;
        }
&nbsp;
        //Rádió be?
        public void CrankTunes(bool state)
        {
            theMusicBox.TurnOn(state);
        }
&nbsp;
        //Kivételt jelez, hogyha a felhasználó a MaxSpeed értéke fölé gyorsítja za autót.
        public void Accelerate(int delta)
        {
            if (CarIsDead)
                Console.WriteLine(&quot;{0} is out of order...&quot;, petName);
            else
            {
                currSpeed += delta;
                if (currSpeed &amp;gt; MaxSpeed)
                {
                    CarIsDead = true;
                    currSpeed = 0;
&nbsp;
                    //Kivétel kiváltása a throw segítségével
                    throw new Exception(string.Format(&quot;{0} has overheated!&quot;,petName));
                }
                else
                    Console.WriteLine(&quot;=&amp;gt; CurrSpeed = {0}&quot;, currSpeed);
            }
        }
&nbsp;
    }
&nbsp;
    class MainClass
    {
        public static void Main()
        {
            Console.WriteLine(&quot;*****Simple Exception Example*****&quot;);
            Console.WriteLine(&quot;=&amp;gt; Creating a car and steppong on it!&quot;);
            var myCar = new Car(&quot;David&quot;, 20); //zippy a neve és jelenleg 20-szal megyünk
            myCar.CrankTunes(true); //rádió bekapcsolva
&nbsp;
            try
            {
                for (int i = 0; i &amp;lt; 10; i++)
                    myCar.Accelerate(10); //10-zel nő a sebesség addig, amíg elnem éri a 100-at, utána felrobban
            }
            catch (Exception ex)
            {
                Console.WriteLine(&quot;*** Error! ***&quot;);
&nbsp;
               //***************************************
                 Console.WriteLine(&quot;Method: {0}&quot;, ex.TargetSite);
                Console.WriteLine(&quot;Class defining member: {0}&quot;,ex.TargetSite.DeclaringType);
                Console.WriteLine(&quot;Member type: {0}&quot;, ex.TargetSite.MemberType);
               //****************************************        
&nbsp;
                Console.WriteLine(&quot;Message: {0}&quot;, ex.Message);
                Console.WriteLine(&quot;Source: {0}&quot;, ex.Source);
            }
&nbsp;
            //A hibát kezeltük, a program FOLYTATÓDIK
            Console.WriteLine(&quot;\n***** Out of Exception logic *****&quot;);
            Console.ReadKey();
        }
    }
&nbsp;
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=94</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kivételkezelés</title>
		<link>http://users.atw.hu/csharpkodok/?p=91</link>
		<comments>http://users.atw.hu/csharpkodok/?p=91#comments</comments>
		<pubDate>Sat, 25 Jul 2009 07:38:37 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>
		<category><![CDATA[kivételkezelés]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=91</guid>
		<description><![CDATA[Kivételkezelés

Kivétel dobása a throw kulcsszó használatával
Először nézzünk egy sima kivétel kezelés nélküli kódot:

using System;
&#160;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if [...]]]></description>
			<content:encoded><![CDATA[<p>Kivételkezelés<br />
<span id="more-91"></span></p>
<p>Kivétel dobása a throw kulcsszó használatával<br />
Először nézzünk egy sima kivétel kezelés nélküli kódot:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
                Console.WriteLine(&quot;Jamming...&quot;);
            else
                Console.WriteLine(&quot;Quite time...&quot;);
        }
    }
&nbsp;
    class Car
    {
        //max sebesség konstansa
        public const int MaxSpeed = 100;
&nbsp;
        //Belső állapot adatok
        private int currSpeed;
        private string petName;
&nbsp;
        //az autó még mindig működőképes?
        private bool CarIsDead;
&nbsp;
        //Az autónak van egy rádiója
        private Radio theMusicBox = new Radio();
&nbsp;
        //Konstruktorok
        public Car() { }
        public Car(string name, int currSp)
        {
            currSpeed = currSp;
            petName = name;
        }
&nbsp;
        //Rádió be?
        public void CrankTunes(bool state)
        {
            theMusicBox.TurnOn(state);
        }
&nbsp;
        //Túlmelegedett az autó?
        public void Accelerate(int delta)
        {
            if (CarIsDead)
                Console.WriteLine(&quot;{0} is out of order...&quot;, petName);
            else
            {
                currSpeed += delta;
                if (currSpeed &gt; MaxSpeed)
                {
                    Console.WriteLine(&quot;{0} has overheated&quot;, petName);
                    currSpeed = 0;
                    CarIsDead = true;
                }
                else
                    Console.WriteLine(&quot;=&gt; CurrSpeed = {0}&quot;, currSpeed);
            }
        }
&nbsp;
&nbsp;
    }
&nbsp;
    class MainClass
    {
        public static void Main()
        {
            Console.WriteLine(&quot;*****Simple Exception Example*****&quot;);
            Console.WriteLine(&quot;=&gt; Creating a car and steppong on it!&quot;);
            var myCar = new Car(&quot;Zippy&quot;, 20); //zippy a neve és jelenleg 20-szal megyünk
            myCar.CrankTunes(true); //rádió bekapcsolva
&nbsp;
            for (int i = 0; i &lt; 10; i++)
                myCar.Accelerate(10); //10-zel nő a sebesség addig, amíg elnem éri a 100-at, utána felrobban
            Console.ReadKey();
        }
    }
&nbsp;
}</pre></div></div>

<p>Most átírjuk a kódot úgy, hogyha az autó átlápi a maxSpeed-et akkor kivételt dobjon:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Radio
    {
        public void TurnOn(bool on)
        {
            if (on)
                Console.WriteLine(&quot;Jamming...&quot;);
            else
                Console.WriteLine(&quot;Quite time...&quot;);
        }
    }
&nbsp;
    class Car
    {
        //max sebesség konstansa
        public const int MaxSpeed = 100;
&nbsp;
        //Belső állapot adatok
        private int currSpeed;
        private string petName;
&nbsp;
        //az autó még mindig működőképes?
        private bool CarIsDead;
&nbsp;
        //Az autónak van egy rádiója
        private Radio theMusicBox = new Radio();
&nbsp;
        //Konstruktorok
        public Car() { }
        public Car(string name, int currSp)
        {
            currSpeed = currSp;
            petName = name;
        }
&nbsp;
        //Rádió be?
        public void CrankTunes(bool state)
        {
            theMusicBox.TurnOn(state);
        }
&nbsp;
        //Kivételt jelez, hogyha a felhasználó a MaxSpeed értéke fölé gyorsítja za autót.
        public void Accelerate(int delta)
        {
            if (CarIsDead)
                Console.WriteLine(&quot;{0} is out of order...&quot;, petName);
            else
            {
                currSpeed += delta;
                if (currSpeed &gt; MaxSpeed)
                {
                    CarIsDead = true;
                    currSpeed = 0;
&nbsp;
                    //Kivétel kiváltása a throw segítségével
                    throw new Exception(string.Format(&quot;{0} has overheated!&quot;,petName));
                }
                else
                    Console.WriteLine(&quot;=&gt; CurrSpeed = {0}&quot;, currSpeed);
            }
        }
&nbsp;
&nbsp;
    }
&nbsp;
    class MainClass
    {
        public static void Main()
        {
            Console.WriteLine(&quot;*****Simple Exception Example*****&quot;);
            Console.WriteLine(&quot;=&gt; Creating a car and steppong on it!&quot;);
            var myCar = new Car(&quot;David&quot;, 20); //zippy a neve és jelenleg 20-szal megyünk
            myCar.CrankTunes(true); //rádió bekapcsolva
&nbsp;
            try // elkapjuk a kivételt, amit létrehoztunk
            {
                for (int i = 0; i &lt; 10; i++)
                    myCar.Accelerate(10); //10-zel nő a sebesség addig, amíg elnem éri a 100-at, utána felrobban
            }
            catch (Exception ex)
            {
                Console.WriteLine(&quot;*** Error! ***&quot;);
                Console.WriteLine(&quot;Method: {0}&quot;, ex.TargetSite);
                Console.WriteLine(&quot;Message: {0}&quot;, ex.Message); //Az üzenet az amit mi hoztunk létre
                Console.WriteLine(&quot;Source: {0}&quot;, ex.Source);
            }
&nbsp;
            //A hibát kezeltük, a program FOLYTATÓDIK
            Console.WriteLine(&quot;\n***** Out of Exception logic *****&quot;);
            Console.ReadKey();
        }
    }
&nbsp;
}</pre></div></div>

<p>Ez csak a példát stitulálja, a való életben nem előnyös a második példát alkalmazni erre a feladatra!</p>
]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=91</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Felüldefiniálások</title>
		<link>http://users.atw.hu/csharpkodok/?p=89</link>
		<comments>http://users.atw.hu/csharpkodok/?p=89#comments</comments>
		<pubDate>Thu, 23 Jul 2009 20:40:16 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[elmélet]]></category>
		<category><![CDATA[kód]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=89</guid>
		<description><![CDATA[ToString() Equals() GetHashCode() felüldefiniálása:


using System;
&#160;
namespace Program
{
    class Person
    {
        public string fName;
        public string lName;
        public sbyte personAge;
&#160;
        public Person(string firstName, [...]]]></description>
			<content:encoded><![CDATA[<p>ToString() Equals() GetHashCode() felüldefiniálása:<br />
<span id="more-89"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Person
    {
        public string fName;
        public string lName;
        public sbyte personAge;
&nbsp;
        public Person(string firstName, string lastName, byte age)
        {
            fName = firstName;
            lName = lastName;
            personAge = (sbyte)age;
        }
        public Person() { }
&nbsp;
        //fölülírjuk a ToStringet
        public override string ToString()
        {
            string myState;
            myState = String.Format(&quot;[First Name: {0}; Last Name: {1}; Age: {2}]&quot;, fName, lName, personAge);
            return myState;
        }
&nbsp;
        //felüldefiniáljuk az Equalst
        public override bool Equals(object obj)
        {
            if (obj is Person &amp;&amp; obj != null)
            {
                Person temp;
                temp = (Person)obj;
                if (temp.fName == this.fName &amp;&amp; temp.lName == this.lName &amp;&amp; temp.personAge == this.personAge)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;
        }
        //visszaadja a ToString() érték alapján kiszámított hashértéket.
        public override int GetHashCode()
        {
            return this.ToString().GetHashCode();
        }
    }
&nbsp;
    class EntryPoint
    {
        public static void Main()
        {
            //Az Equals() és a GetHashCode() teszteléséhez
            //ezeknek egyezniük kell.
            var p1 = new Person(&quot;Homer&quot;, &quot;Simpson&quot;, 50);
            var p2 = new Person(&quot;Homer&quot;, &quot;Simpson&quot;, 50);
&nbsp;
            //Az objektum szöveges verziójának beolvasása
            Console.WriteLine(&quot;p1.ToString() {0}&quot;,p1.ToString());
            Console.WriteLine(&quot;p2.ToString() {0}&quot;, p2.ToString());
&nbsp;
            //a felülbírált Equals() tesztelése
            Console.WriteLine(&quot;p1 = p2?: {0}&quot;, p1.Equals(p2));
&nbsp;
            //a hashérték tesztelése.
            Console.WriteLine(&quot;Same hash codes?: {0}&quot;, p1.GetHashCode() == p2.GetHashCode());
            Console.WriteLine();
&nbsp;
            //A p2 korának módosítása, és ismételt tesztelése.
            p2.personAge = 45;
            Console.WriteLine(&quot;p1.ToString() {0}&quot;, p1.ToString());
            Console.WriteLine(&quot;p2.ToString() {0}&quot;, p2.ToString());
            Console.WriteLine(&quot;p1 = p2?: {0}&quot;, p1.Equals(p2));
            Console.WriteLine(&quot;Same hash codes?: {0}&quot;, p1.GetHashCode() == p2.GetHashCode());
            Console.WriteLine();
&nbsp;
&nbsp;
            Console.ReadKey();
        }
    }
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=89</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A toString felüldefiniálása</title>
		<link>http://users.atw.hu/csharpkodok/?p=87</link>
		<comments>http://users.atw.hu/csharpkodok/?p=87#comments</comments>
		<pubDate>Thu, 23 Jul 2009 20:38:26 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>
		<category><![CDATA[ToString felüldefiniálása]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=87</guid>
		<description><![CDATA[A System.Object.ToString() felüldefiniálása


using System;
&#160;
namespace Program
{
    class Person 
    {
        public string fName;
        public string lName;
        public sbyte personAge;
&#160;
        public Person(string firstName, [...]]]></description>
			<content:encoded><![CDATA[<p>A System.Object.ToString() felüldefiniálása<br />
<span id="more-87"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Person 
    {
        public string fName;
        public string lName;
        public sbyte personAge;
&nbsp;
        public Person(string firstName, string lastName, byte age)
        {
            fName = firstName;
            lName = lastName;
            personAge =(sbyte) age;
        }
        public Person() { }
&nbsp;
        //fölülírjuk a ToStringet
        public override string ToString()
        {
            string myState;
            myState = String.Format(&quot;[First Name: {0}; Last Name: {1}; Age: {2}]&quot;, fName, lName, personAge);
            return myState;
        }
    }
&nbsp;
    class EntryPoint
    {
        public static void Main()
        {
            var p1 = new Person(&quot;Ruud&quot;,&quot;Vannistelrooy&quot;,37);
&nbsp;
            Console.WriteLine(&quot;ToString: {0}&quot;, p1.ToString()); //Az íródik ki, amivel felülírtuk a toStringet...
            Console.WriteLine(&quot;Hash code: {0}&quot;, p1.GetHashCode());
            Console.WriteLine(&quot;Type: {0}&quot;, p1.GetType());
&nbsp;
            Person p2 = p1;
            object o = p2;
&nbsp;
            //Az equals megviszgálja, hogy az értékek ugyan arra a memóriahelyre hivatkoznak-e és ha igen true-val térnek vissza
            if (o.Equals(p1) &amp;&amp; p2.Equals(o))
            {
                Console.WriteLine(&quot;Same instance!&quot;);
            }
            Console.WriteLine();
&nbsp;
            Console.ReadKey();
        }
    }
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://users.atw.hu/csharpkodok/?feed=rss2&amp;p=87</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Equals</title>
		<link>http://users.atw.hu/csharpkodok/?p=84</link>
		<comments>http://users.atw.hu/csharpkodok/?p=84#comments</comments>
		<pubDate>Thu, 23 Jul 2009 20:36:41 +0000</pubDate>
		<dc:creator>nameless</dc:creator>
				<category><![CDATA[kód]]></category>
		<category><![CDATA[equals]]></category>

		<guid isPermaLink="false">http://users.atw.hu/csharpkodok/?p=84</guid>
		<description><![CDATA[Equals:


using System;
&#160;
namespace Program
{
    class Person { }
&#160;
    class EntryPoint
    {
        public static void Main()
        {
            var p1 = new Person();
  [...]]]></description>
			<content:encoded><![CDATA[<p>Equals:<br />
<span id="more-84"></span></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">using System;
&nbsp;
namespace Program
{
    class Person { }
&nbsp;
    class EntryPoint
    {
        public static void Main()
        {
            var p1 = new Person();
                                                                                //névtér.típus
            Console.WriteLine(&quot;ToString: {0}&quot;, p1.ToString());
            Console.WriteLine(&quot;Hash code: {0}&quot;, p1.GetHashCode()); // egy egész számmal tér vissza, amely egy adott objektumpéldányt azonosít
            Console.WriteLine(&quot;Type: {0}&quot;, p1.GetType()); 
&nbsp;
            Person p2 = p1;
            object o = p2;
&nbsp;
            //Az equals megviszgálja, hogy az értékek ugyan arra a memóriahelyre hivatkoznak-e és ha igen true-val térnek vissza
            if (o.Equals(p1) &amp;&amp; p2.Equals(o))
            {
                Console.WriteLine(&quot;Same instance!&quot;);
            }
            Console.WriteLine();
&nbsp;
            Console.ReadKey();
        }
    }
}</pre></div></div>

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