This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Nullable | |
| DateTime? date = Request.QueryString["date"].ToOrDefault<DateTime?>(); | |
| if(date.HasValue) { | |
| <meinObjekt>.Date = date.Value; | |
| } | |
| // Kein Nullable | |
| Guid guid = Request.Form["userGuid"].ToOrDefault<Guid>(); | |
| if(guid != Guid.Empty) | |
| currentUser = User.Load(guid); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static partial class Common | |
| { | |
| /// <summary> | |
| /// Gibt ein typisiertes Objekt aus einem String zurück. | |
| /// Falls die Umwandlung nicht erfolgreich ist, wird stattdessen | |
| /// der Standardwert des Zieltypen zurückgegeben. | |
| /// </summary> | |
| /// <typeparam name="T">Zieltyp</typeparam> | |
| /// <param name="value">Zu typisierenden String</param> | |
| /// <param name="defaultValue">Standardwert (Wird bei Fehlschlag zurückgegeben)</param> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int typedValue = Request.QueryString["index"].ToOrDefault<int>(); | |
| if(typedValue == 4) { | |
| lblStatus.Text = string.Format("Wert gültig: {0}", typedValue); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string value = Request.QueryString["index"]; // Kann auch das Literal "null" darstellen | |
| int typedValue; | |
| if(int.TryParse(value, out typedValue) && typedValue == 4) { | |
| lblStatus.Text = string.Format("Wert gültig: {0}", typedValue); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Foo(ref m); | |
| static void Foo(ref Mensch MenschArgument) { | |
| //... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace ParameteruebergabeInCSharp { | |
| class Program { | |
| static void Main(string[] args) { | |
| // Wir erstellen unser Objekt und füllen die Eigenschaft "Name" | |
| Mensch m = new Mensch(); | |
| m.Name = "Peter"; | |
| // Wir rufen unsere Funktion auf und übergeben unser Mensch Objekt | |
| // an die Methode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Deklarierung, jedoch keine Initialisierung unserer Ergebnisparameter | |
| string meinName; | |
| int meinAlter; | |
| // Aufruf unserer Methode | |
| MeineMethode(out meinName, out meinAlter); | |
| Console.WriteLine(meinName); // Gibt Peter aus | |
| Console.WriteLine(meinAlter); // Gibt 23 aus | |
| // Deklarierung unserer Methode und Zuweisung der gewünschten Werte | |
| public void MeineMethode(out string meinNameArgument, out int meinAlterArgument) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Variable deklarieren und initialisieren: | |
| int meineVariable = 1; | |
| // Aufruf unserer Methode und anschliessende Ausgabe unserer Variable in der Konsole meineMethode(ref meineVariable); | |
| MeineMethode(ref meineVariable); | |
| Console.WriteLine(meineVariable.ToString()); // Gibt 4 aus | |
| // Deklarierung unserer Methode und Veränderung des Arguments | |
| public void MeineMethode(ref int meinArgument) { | |
| // Wir weisen unserem Argument den Wert 4 zu. Da per "ref" Schlüsselwort die Referenz (Zeiger) auf unsere Variable "meineVariable" übergeben wird, | |
| // ändert sich auch der Wert unserer Variable. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Variable deklarieren und initialisieren: | |
| int meineVariable = 1; | |
| // Aufruf unserer Methode und Ausgabe unserer Variable in der Konsole | |
| meineMethode(meineVariable); | |
| Console.WriteLine(meineVariable.ToString()); // Gibt 1 aus | |
| // Deklarierung unserer Methode und Gebrauch des Arguments | |
| public void MeineMethode(int meinArgument) { | |
| // Wir weisen unserem Argument einen neuen Wert zu. | |
| // Diese Änderung ist nur innerhalb unserer Methode gültig und hat keine Auswirkungen auf unsere ursprüngliche Variable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Aufruf der Methode mit Ergebnisparameterübergabe (Schlüsselwort: out) | |
| MeineMethode(out meinErgebnisParameter); |
NewerOlder