<?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>Significant Bit</title>
	<atom:link href="http://significantbit.net/feed" rel="self" type="application/rss+xml" />
	<link>http://significantbit.net</link>
	<description>... a little Bit smarter!</description>
	<lastBuildDate>Wed, 16 Mar 2011 13:59:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Design Patterns: Singleton</title>
		<link>http://significantbit.net/design-patterns-singleton</link>
		<comments>http://significantbit.net/design-patterns-singleton#comments</comments>
		<pubDate>Fri, 18 Feb 2011 07:00:24 +0000</pubDate>
		<dc:creator>Dustin Klein</dc:creator>
				<category><![CDATA[Entwicklung]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[entwicklung]]></category>
		<category><![CDATA[Methoden]]></category>

		<guid isPermaLink="false">http://significantbit.net/?p=105</guid>
		<description><![CDATA[<p>Posted in <a href="http://significantbit.net/tumblog/articles">Articles</a></p>Oftmals ist es nicht schwer, ein kleines Stück Software oder ein gutes Tool zu entwickeln. Doch was tun, wenn man ein wesentlich größeres und aufwendigeres Projekt realisieren möchte. Ich stand auch schon häufig vor diesem &#8220;Problem&#8221;, da ich häufig keinen passenden Anfang finde. Wenn das Grundkonzept steht möchte man viel zu oft schnell ans Programmieren. [...]]]></description>
			<content:encoded><![CDATA[<p>Oftmals ist es nicht schwer, ein kleines Stück Software oder ein gutes Tool zu entwickeln. Doch was tun, wenn man ein wesentlich größeres und aufwendigeres Projekt realisieren möchte. Ich stand auch schon häufig vor diesem &#8220;Problem&#8221;, da ich häufig keinen passenden Anfang finde. Wenn das Grundkonzept steht möchte man viel zu oft schnell ans Programmieren. Generell auch eine feine Sache, die von Enthuisasmus zeugt. Aber Vorsicht! Klassen einfach drauf los zu programmieren ist eine Todsünde!</p>
<p><a href="http://significantbit.net/wp-content/uploads/2011/02/singleton_db_factory1.png"><img class="aligncenter size-full wp-image-114" title="DAL mit Singleton" src="http://significantbit.net/wp-content/uploads/2011/02/singleton_db_factory1.png" alt="DAL mit Singleton" width="500" height="346" /></a></p>
<p>Es ist zwangsläufig notwendig, sich vorher mit seinen Klassen auseinander zu setzen, um nicht später alles über den Haufen werfen zu müssen, wenn man merkt, dass man etwas wichtiges vergessen hat. In diesem Prozess sind sogenannte <strong>Design Patterns</strong> von absoluter Notwendigkeit! Diese <strong>Entwicklungs Muster</strong> dienen dazu, grundsätzliche Strukturen und Verfahren in Euer Programm zu bringen. Ich möchte mich im ersten Teil dieser Serie mit dem <strong>Singleton</strong>, also der Einmal-Instanzierung einer Klasse, beschäftigen.<br />
<span id="more-105"></span><br />
Fängt man ein neues Projekt an, so hat man meistens einen Basis-Layer, der die Verbindungungen mit Datenbanken reglementiert (Database Access Layer [DAL]) oder Konfigurationen aus einer XML oder anderen Formaten ausliest. Gerade beim DAL ist es von bedeutender Relevanz, dass pro Anwendung nur eine einzige DAL-Initiierung erfolgen darf! Man möchte schließlich nicht 3 oder 4 Mal die gleiche Datenbank mit unterschiedlichen Objekten, mit vielleicht sogar unterschiedlichen Parametern ansprechen.</p>
<p>Der Design Pattern &#8220;Singleton&#8221; reglementiert die Instanzierung von Klassen. Dabei ist die theoretische Vorgehensweise sehr einfach. Wichtig ist zuersteinmal, dass wir den Konstruktor von außen nicht mehr zugänglich machen. Dieser ist nun <em>private</em> und kann nur vom Singleton aufgerufen werden. Soweit, so gut. Nun müssen wir uns überlegen, wie wir prüfen können, ob es bereits eine Instanz unserer Klasse gibt. Das machen wir indem wir in der Klasse eine Variable vom Typ der zu überwachenden Klasse anlegen und auf <em>NULL</em> setzen.</p>
<p>Der Singleton</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> volatile Klassenname _instance <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> m_lock <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> Klassenname GetInstance<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_instance <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">lock</span><span style="color: #008000;">&#40;</span>m_lock<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_instance <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        _instance <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Klassenname<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">return</span> _instance<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Diese Methodik bezeichnet auch schon den Singleton. Wir prüfen, ob eine Instanz der Klasse angelegt wurde. Ist dies nicht der Fall, sperren wir den folgenden Code für weitere Threads, die eventuell auf diese Klasse zugreifen könnten und prüfen erneut, ob eine Instanz vorliegt (DoubleLock). Ist dies nun immernoch nicht der Fall, so erzeugen wir eine neue Instanz, rufen also den Konstruktor auf.</p>
<p>Nun wurde die Variable _instance auf die gerade erzeugte Instanz festgelegt und kann bei jedem weiteren Aufruf von GetInstance() an das Objekt vom Typen Klassenname zurückgegeben werden. Doch wofür das alles? Ganz einfach: Wir brauchen keine Objekte mehr zwischen mehreren Klassen hin und her zu übergeben. Diese Klassen können nun mit GetInstance() einfach der vollständig initialisierte Klasse holen und mit all ihren Werten und Parametern arbeiten.</p>
<p>GetInstance() im Einsatz</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Aufruf der Klassen-Instanz</span>
Klassenname myClass <span style="color: #008000;">=</span> Klassenname<span style="color: #008000;">.</span><span style="color: #0000FF;">GetInstance</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Aufruf mit Hilfe eines Interfaces</span>
IKlassenname myClass <span style="color: #008000;">=</span> Klassenname<span style="color: #008000;">.</span><span style="color: #0000FF;">GetInstance</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Diese Vorgehensweise lässt sich auch ideal erweitern, falls Ihr nur eine gewisse Anzahl an Instanzen zulassen wollte. Sowas kann gebraucht werden, wenn man Zugriff auf mehr als eine Datenbank haben möchte. In diesem Fall kann man dem Singleton noch Parameter übergeben, welche er dazu nutzen kann, ebenfalls den Konstruktor parameterisiert aufzurufen. Probiert es aus, Euch sind so gut wie keine Grenzen gesetzt!</p>
]]></content:encoded>
			<wfw:commentRss>http://significantbit.net/design-patterns-singleton/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: Erweiterungsmethoden</title>
		<link>http://significantbit.net/c-erweiterungsmethoden</link>
		<comments>http://significantbit.net/c-erweiterungsmethoden#comments</comments>
		<pubDate>Thu, 27 Jan 2011 15:01:20 +0000</pubDate>
		<dc:creator>Dustin Klein</dc:creator>
				<category><![CDATA[Entwicklung]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[entwicklung]]></category>
		<category><![CDATA[Methoden]]></category>

		<guid isPermaLink="false">http://significantbit.net/?p=99</guid>
		<description><![CDATA[<p>Posted in <a href="http://significantbit.net/tumblog/articles">Articles</a></p>Die Sprache bietet ja so oder so schon ziemlich nette Annehmlichkeiten. So habe ich bei Variablen des Typen &#8220;string&#8221; bereits einige nützliche Methoden zur Auswahl wie ToLower(), ToUpper(), Trim(), Remove(), Replace(), Split(), ToCharArray() und viele mehr. Diese erledigen für Otto-Normal-Programmierer wohl 80 % der täglichen Arbeit. Doch was tun, wenn genau diese Funktionen nicht mehr [...]]]></description>
			<content:encoded><![CDATA[<p>Die Sprache bietet ja so oder so schon ziemlich nette Annehmlichkeiten. So habe ich bei Variablen des Typen &#8220;string&#8221; bereits einige nützliche Methoden zur Auswahl wie ToLower(), ToUpper(), Trim(), Remove(), Replace(), Split(), ToCharArray() und viele mehr. Diese erledigen für Otto-Normal-Programmierer wohl 80 % der täglichen Arbeit.</p>
<p>Doch was tun, wenn genau diese <strong>Funktionen</strong> nicht mehr helfen können oder ein Workaround zu unschönem und unübersichtlichem Quelltext führen? Genau dafür bringt <strong>C#</strong> eine pfiffige Lösung: Die <strong>Erweiterungsmethoden</strong>.<br />
<span id="more-99"></span><br />
Fangen wir erstmal vorne an. Erweiterungsmethoden dienen, wie der Name schon sagt, zum Erweitern von Objekten. Es können also im Prinzip jedem Objekt Funktionen nachträglich beigebracht werden. Das ist immer dann von Vorteil, wenn man komplexere Prüfungen oder Verfahren jedem Objekt verfügbar machen möchte, ohne dabei neue Klassen o.ä. zu erstellen.</p>
<p>Nehmen wir als Beispiel eine Variable vom Typ string. Neben vielen schönen Funktionen gäbe es aber in manchen Anwendungsgebieten auch die Notwendigkeit weiterer Funktionen. Gerade bei Textverarbeitung o.ä. wäre es gut, wenn wir eine Funktion hätten, die uns die Anzahl der Worte oder der Umlaute zurückgibt.</p>
<p>Dazu erstellen wir eine statische Klasse mit einer statischen Methode. Als Übergabe Parameter bekommen Erweiterungsmethoden immer ein &#8220;this&#8221; und dahinter folgt der Typ, der erweitert werden soll, samt Variablennamen für die Funktion.</p>
<p>Wörter zählen:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> WordCount<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> str<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> str<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">' '</span>, StringSplitOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveEmptyEntries</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">string</span> meinText <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Das ist nur ein kleiner Test!&quot;</span>
<span style="color: #6666cc; font-weight: bold;">int</span> anz <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
anz <span style="color: #008000;">=</span> meinText<span style="color: #008000;">.</span><span style="color: #0000FF;">WordCount</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// anz = 5</span></pre></div></div>

<p>Schon haben wir die Möglichkeit uns die Anzahl an Wörtern zurückgeben zu lassen. Das Gleiche funktioniert auch wunderbar mit Sonderzeichen, was man gebrauchen könnte, sobald Sonderzeichen einen Fehler auslösen oder Ähnliches.</p>
<p>Sonderzeichen zählen:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> SpecialCount<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> str<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> str<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">'ö'</span>, <span style="color: #666666;">'ü'</span>, <span style="color: #666666;">'ä'</span>, <span style="color: #666666;">'?'</span> <span style="color: #008000;">&#125;</span>, StringSplitOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveEmptyEntries</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">string</span> meinText <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Däs ist nür ein kleiner Teßt!&quot;</span>
<span style="color: #6666cc; font-weight: bold;">int</span> anz <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
anz <span style="color: #008000;">=</span> meinText<span style="color: #008000;">.</span><span style="color: #0000FF;">SpecialCount</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// anz = 3</span></pre></div></div>

<p>Es gibt noch eine Vielzahl von Möglichkeiten für eine solche Funktion. Anzahl an Kommentaren, Zeilenumbrüchen und viele mehr. In manchen Einsatzgebieten ist es allerdings notwendig den eigenen Wert der Variable zu ändern und diese nicht via &#8220;return&#8221; an eine weitere Variable weiterzugeben. Leider erlaubt uns C# hier nur die Weitergabe über einen out Parameter, den wir dann nutzen können.</p>
<p>Werte setzen:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsZero<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">int</span> oldValue, <span style="color: #0600FF; font-weight: bold;">out</span> <span style="color: #6666cc; font-weight: bold;">int</span> newValue, <span style="color: #6666cc; font-weight: bold;">int</span> max<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>oldValue <span style="color: #008000;">&gt;</span> max<span style="color: #008000;">&#41;</span>
    newValue <span style="color: #008000;">=</span> max<span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">int</span> zahl <span style="color: #008000;">=</span> <span style="color: #FF0000;">1020</span><span style="color: #008000;">;</span>
zahl<span style="color: #008000;">.</span><span style="color: #0000FF;">IsGreater</span><span style="color: #008000;">&#40;</span>zahl, <span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// zahl = 1000;</span></pre></div></div>

<p>Wir können bei den Erweiterungsmethoden aber nicht auf einen Return-Type verzichten. Das heißt, dass jede Funktion einen Rückgabe-Wert haben muss. Ich hoffe, ich konnte Euch diese Art der Variablen-Nutzung ein wenig näher bringen und wünsche viel Spaß beim Testen &#8211; Cherryo!</p>
<p><strong>Wie immer gilt: Dies ist freier Code, Ihr könnt Ihn einsetzen, wie und wo Ihr wollt!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://significantbit.net/c-erweiterungsmethoden/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parameter und Schalter in Konsolenanwendungen</title>
		<link>http://significantbit.net/parameter-schalter-konsolenanwendungen</link>
		<comments>http://significantbit.net/parameter-schalter-konsolenanwendungen#comments</comments>
		<pubDate>Sun, 23 Jan 2011 20:00:00 +0000</pubDate>
		<dc:creator>Dustin Klein</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[entwicklung]]></category>

		<guid isPermaLink="false">http://significantbit.net/parameter-und-schalter</guid>
		<description><![CDATA[<p>Posted in <a href="http://significantbit.net/tumblog/articles">Articles</a></p>Und am siebten Tage schuf Microsoft die Konsole. &#8211; So oder so ähnlich könnte man heute auf die Vergangenheit der modernen, fensterbasierenden Programmierung zurückblicken. Vorbei die Zeit in der ominöse kleine schwarze Kommandozeilen über unsere Monitore flackerten und auf Benutzereingaben warteten. Doch hin und wieder ertappt man sich selber, wie man wieder in gewohnte Muster [...]]]></description>
			<content:encoded><![CDATA[<p>Und am siebten Tage schuf Microsoft die Konsole. &#8211; So oder so ähnlich könnte man heute auf die Vergangenheit der modernen, fensterbasierenden Programmierung zurückblicken. Vorbei die Zeit in der ominöse kleine schwarze Kommandozeilen über unsere Monitore flackerten und auf Benutzereingaben warteten.</p>
<p><a href="http://significantbit.net/wp-content/uploads/2011/01/parameter-und-schalter-in-konsolenanwendungen.png"><img src="http://significantbit.net/wp-content/uploads/2011/01/parameter-und-schalter-in-konsolenanwendungen.png" alt="Parameter und Schalter in Konsolenanwendungen" title="parameter-und-schalter-in-konsolenanwendungen" width="525" height="265" class="aligncenter size-full wp-image-95" /></a></p>
<p>Doch hin und wieder ertappt man sich selber, wie man wieder in gewohnte Muster zurückfällt und auf eine ansehliche Oberfläche verzichtet. Genau hier möchte ich mit dem ersten Blog-Eintrag einhaken. Wie sollte ein solches Projekt beginnen? Was ist zu beachten?</p>
<p>Das Erste, womit man sich beschäftigen sollte, sofern benötigt, ist die Übergabe von Parametern und Schaltern.<br />
<span id="more-14"></span><div class="box"><div class="icon icon-info left" style="background-image: url(http://significantbit.net/wp-content/themes/fastblog/images/icons/info.png);">Wer den Parameter nicht ehrt, ist die Anwendung nicht wert!</div></div></p>
<p>Bei mir ein gern genutztes Sprichwort. In den meisten Anwendungen ist es sinnvoll, dem Nutzer die Möglichkeit zu bieten, die Nutzung der Anwendung zu optimieren, indem er Parameter oder Schalter hinzufügen kann. Ich denke, jeder hat solche Konsolenanwendungen bereits gesehen.</p>
<div class="box"><div class="icon icon-info left" style="background-image: url(http://significantbit.net/wp-content/themes/fastblog/images/icons/info.png);">Da es sich hier um eine Norm im Bereich der Entwicklung handelt, werden Parameter grundsätzlich mit einem Bindestrich und Schalter mit einem Schrägstrich begonnen, so dass wir folgendes Muster erhalten:<br />
&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Programm<span style="color: #008000;">.</span><span style="color: #0000FF;">exe</span> <span style="color: #008000;">-</span>a para1 <span style="color: #008000;">-</span>b para2 <span style="color: #008000;">/</span>schalter1 <span style="color: #008000;">/</span>schalter2</pre></div></div>
</div></div>
<p>Diese Werte sollten optimal vom Programm abgefangen werden, ohne aber zu viel Zeit darauf zu verschwenden. Ich nutze hierfür immer gerne eine kleine Parameter-Klasse. Diese besteht aus allen Variablen, die über Parameter (int, string, char, double, etc.) oder Schalter (bool) übergeben werden können. Zusätzlich enthält sie noch zwei Funktionen mit denen es möglich ist, zu überprüfen, welche Werte ein entsprechender Parameter hat oder ob ein Schalter aktiviert ist.</p>
<p><strong>Die Grundfunktionen (C#):</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Parameter auswerten</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetArgument<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> ArgName<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// Alle Parameter durchlaufen</span>
  <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> Arguments<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Wurde das Keyword gefunden, Wert zurückliefern</span>
    <span style="color: #008080; font-style: italic;">// Hierbei wird auf den Bindestrich geprüft und ob ein Wert folgt</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Arguments<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;-&quot;</span> <span style="color: #008000;">+</span> ArgName <span style="color: #008000;">&amp;&amp;</span> Arguments<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;=</span> i<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0600FF; font-weight: bold;">return</span> Arguments<span style="color: #008000;">&#91;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #008080; font-style: italic;">// Wenn nichts gefunden wurde, Leerstring zurückgeben</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Schalter auswerten</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> GetSwitch<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> SwitchName<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Alle Parameter durchlaufen</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> item <span style="color: #0600FF; font-weight: bold;">in</span> Arguments<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Wurde ein Schalter gefunden, TRUE zurückgeben</span>
        <span style="color: #008080; font-style: italic;">// Beim Schalter prüfen wir auf den Schrägstrich</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>item<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/&quot;</span> <span style="color: #008000;">+</span> SwitchName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Hiermit habe ich nun zwei Funktionen die mir, mit Übergabe der Namen der Parameter oder Schalter, die passenden Werte zurückliefern. Optimal lässt sich dies in der Parameter-Klasse im Konstruktor einbauen, so dass man direkt ein entsprechendes Objekt nutzen kann, ohne weiter auf die Funktionen zurückzugreifen.</p>
<p><strong>Die gesamte Klasse (C#):</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">namespace</span> MyProgramm
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> ArgumentHandler
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Übergabevariablen</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> Arguments<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Variablendeklaration</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">string</span> para1<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">long</span> para2<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">int</span> para3<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">bool</span> switch1<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">bool</span> switch2<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Getter &amp; Setter</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Para1 <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _para1<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">long</span> Para2 <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _para2<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Para3 <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _para3<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Switch1 <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _switch1<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Switch2 <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _switch2<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Konstruktor</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> ArgumentHandler<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Arguments <span style="color: #008000;">=</span> args<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Diese liefert mir meine Main-Klasse</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Variableninitialisierung</span>
            _para1 <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
            _para2 <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            _para3 <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
            _switch1 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            _switch2 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Prüfen, ob Kernelemente gesetzt sind</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> CheckArguments<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                _para1 <span style="color: #008000;">=</span> GetParameter<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;para1&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">long</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>GetParameter<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;para2&quot;</span><span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> _para2<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>GetParameter<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;para3&quot;</span><span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> _para3<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                _switch1 <span style="color: #008000;">=</span> GetSwitch<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;switch1&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                _switch2 <span style="color: #008000;">=</span> GetSwitch<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;switch2&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Prüfen ob vorhanden</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>_para1<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_para2 <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_para3 <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">catch</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetArgument<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> ArgName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> Arguments<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Arguments<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;-&quot;</span> <span style="color: #008000;">+</span> ArgName <span style="color: #008000;">&amp;&amp;</span> Arguments<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;=</span> i<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> Arguments<span style="color: #008000;">&#91;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> GetSwitch<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> SwitchName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> item <span style="color: #0600FF; font-weight: bold;">in</span> Arguments<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>item<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/&quot;</span> <span style="color: #008000;">+</span> SwitchName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Wie immer gilt:</strong> Dies ist freier Code, Ihr könnt Ihn einsetzen, wie und wo Ihr wollt!</p>
]]></content:encoded>
			<wfw:commentRss>http://significantbit.net/parameter-schalter-konsolenanwendungen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Die 10. Dimension</title>
		<link>http://significantbit.net/die-zehnte-dimension</link>
		<comments>http://significantbit.net/die-zehnte-dimension#comments</comments>
		<pubDate>Sun, 23 Jan 2011 19:30:00 +0000</pubDate>
		<dc:creator>Dustin Klein</dc:creator>
				<category><![CDATA[Mathematik]]></category>
		<category><![CDATA[Physik]]></category>

		<guid isPermaLink="false">http://significantbit.net/die-10-dimension-2</guid>
		<description><![CDATA[<p>Posted in <a href="http://significantbit.net/tumblog/video">Video</a></p><p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/8Q_GQqUg6Ts?fs=1&amp;hl=de_DE"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/8Q_GQqUg6Ts?fs=1&amp;hl=de_DE" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>Für alle, die sich gerne Partywissen aneignen möchten oder einfach Interesse an der Mathematik und der Physik haben, habe ich hier ein schönes Video, welches sich an der Erklärung der 10 Dimensionen versucht. Man muss hier allerdings beachten, dass dies nicht die offiziell anerkannte Variante der String-Theorie ist. Vielmehr beruft man sich hier auf der [...]]]></description>
			<content:encoded><![CDATA[<p>Für alle, die sich gerne Partywissen aneignen möchten oder einfach Interesse an der Mathematik und der Physik haben, habe ich hier ein schönes Video, welches sich an der Erklärung der 10 Dimensionen versucht.<br />
<span id="more-56"></span><br />
Man muss hier allerdings beachten, dass dies nicht die offiziell anerkannte Variante der String-Theorie ist. Vielmehr beruft man sich hier auf der Grundlage des Buches &#8220;Imaging the Tenth Dimension&#8221; von Rob Bryanton. Dennoch wurde eine anschauliche Interpretation geschaffen.</p>
]]></content:encoded>
			<wfw:commentRss>http://significantbit.net/die-zehnte-dimension/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
