diff options
author | Adam Bard <github@adambard.com> | 2013-08-17 09:27:23 -0700 |
---|---|---|
committer | Adam Bard <github@adambard.com> | 2013-08-17 09:27:23 -0700 |
commit | 1eec8e47bc014f3d9e26abce62623c4ea6cc3925 (patch) | |
tree | fc083a727783312bfc4d2a5ec8e1271d7db3b223 | |
parent | 6c3afe88ab026ddd855bc05a126256efa9764fe1 (diff) | |
parent | c3df13db567b82fc0802e46c23e4e4486618b207 (diff) |
Merge pull request #245 from golergka/master
Minor additions to C#
-rw-r--r-- | csharp.html.markdown | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/csharp.html.markdown b/csharp.html.markdown index c254b5a9..0cef8f05 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -144,6 +144,10 @@ namespace Learning int? nullable = null; Console.WriteLine("Nullable variable: " + nullable); + // In order to use nullable's value, you have to use Value property or to explicitly cast it + string? nullableString = "not null"; + Console.WriteLine("Nullable value is: " + nullableString.Value + " or: " + (string) nullableString ); + // ?? is syntactic sugar for specifying default value // in case variable is null int notNullable = nullable ?? 0; @@ -418,10 +422,10 @@ namespace Learning public Bicycle(int startCadence, int startSpeed, int startGear, string name, bool hasCardsInSpokes) { - this.gear = startGear; + this.gear = startGear; // "this" keyword denotes the current object this.cadence = startCadence; this._speed = startSpeed; - this.name = name; + this.name = name; // it can be useful when there's a name conflict this.hasCardsInSpokes = hasCardsInSpokes; } @@ -470,19 +474,19 @@ namespace Learning // when only data needs to be accessed, consider using properties. // properties may have either get or set, or both private bool _hasTassles; // private variable - public bool hasTassles // public accessor + public bool HasTassles // public accessor { get { return _hasTassles; } set { _hasTassles = value; } } - private int _frameSize; + // Properties can be auto-implemented public int FrameSize { - get { return _frameSize; } + get; // you are able to specify access modifiers for either get or set // this means only Bicycle class can call set on Framesize - private set { _frameSize = value; } + private set; } //Method to display the attribute values of this Object. |