Skip to main content

Posts

Showing posts with the label c# 8

C# 8 is becoming too terse and it's going to backfire

I love working in C#, plain and simple. C# gets the job done, but - in it's latest preview, it's becoming too terse. Let me explain. A 'nifty logo don't you say? Patterns Have you ever heard of them? Well, besides software design patterns  or if you are hungry, cookie patterns , there is something called pattern matching in C# 7 and it is pretty handy. If you've never used pattern matching before, you can check if a variable is of a certain type and assign this variable to a new variable in a single line. The example below explains how this will work. Using the is type pattern expression Perhaps I haven't given it much thought to make use of this yet, but this feature out there and it makes sense. There really isn't any indication that we are assigning a variable in the code, we aren't using an equal sign or semi colon on the line, but still, it is an easy concept to learn. This new feature in C# 7 is not any more complicated than a ...

Do you choose inheritance or interfaces?

What's the right answer? The answer to every programming question Let's explore both options and when you might choose to prefer one or the other. Pay extra special attention and focus because this is a common job question and an answer you should fundamentally know if you want to become a better software developer! Why choose interfaces? Choose inheritance when your objects have a has-a or can-do relationship. What does this mean? A has-a relationship means the object implementing the interface "has a" object/thing that is the interface. Here is a concrete example of a has-a relationship: public interface IWheel { public void TurnRight ( ) ; public void TurnLeft ( ) ; } public class Boat : IWheel { public void TurnRight ( ) { // implementation } public void TurnLeft ( ) { // implementation } } A boat has a wheel, and is an example of using an interface with a has-a relatio...