C# Exploration

Sunday, December 28, 2014

Dynamic keyword, no checking at compile time, only at run time


Named argument, the argument at calling site has a name


Optional parameter, must come after all required parameters


Create a failing test


Create a passing test


Add this class with method to elements project


A test to check that the value is what expected to be


Add a parameter to the method and append it to the return value


Pass in an argument into method invocation and check the return value


Add a second test to check with a different name


Update the class with a field, constructor that initializes the field and the method appends the sender variable


Update the test, pass the sender name in the constructor, check the return value in the assert


If the field is only ever set in the constructor or variable initializer, set it to readonly


Use double slashes for code comments


Slash star, star slash is for a multiline comment


Triple slashes generates a comment structure for xml documentation


Check if sender is null, if yes just return greeting to receiver


Pass in null in the constructor, the test passes


When receiver is null throw an exception


The unit test to check that the exception was thrown


Add a property with a getter, readonly returns the field


A unit test to test that the property is set from the constructor


Equality for strings is case sensitive


Remove the readonly keyword from the field and add a setter to the property


Test that sender property is writeable and sender text is what expected


Automatic property


Make the setter part of the property private


Biginteger type represents any arbitrarily sized integer


Floating point numbers


Printing currencies


Not a number, a nan is not equal to another nan


Test the length of a string


Strings are reference types and immutable


The objects are refering to different objects


The strings don't refer to the same object in memory but they are equal


A and b refer to the same objects


Bad concatenation


Good concatenation, stringbuilder is sort of like a mutable string, takes five ms as opposed to seven seconds


Bad use of string builder


Good Use of concatenation


Default Success Warning Important Info Inverse
B S W I ? O