Monthly Archives: Maj 2017

[EN] Get Noticed 2017 – summary

It’s time to write short summary about Get Noticed 2017 challenge, because it is going to finish at the end of this month.
Well, I can admit it was a good time. It gave me a lot. This challenge motivated me everyday to learn new things and write about it on my blog. I chose to create an application using ASP.NET Core WebApi and Angular2 – ELP. Unfortunately I haven’t finished my app yet, but it’s important I tried to and finally I found a time to work on it in my spare time, after work.

I want to continue work on the ELP application in the next months to finish it some day
and release, I want to finish it by the end of the year, but we will se how it goes.

Blogging takes a lot of time so I will write less frequent than previously, to focus more on coding, but I’m not going to stop blogging so I encourage you to add my blog to your feeds, to be updated.

During DSP/Get Noticed 2017 I realized that it’s very hard to do pet projects after working hours
and focus on them in 100%. How much time do you have after work? I mean free time when you can do nothing. From my observations it’s about 2-3 hours.
You can spend all night of course, but the point is to do something after hours and be productive next day as well. What do you think about it? You can write me in a comment. It’s always a lack of time and because of it, some programmers
quit their job to have more time to focus on their projects. It’s also an option to consider –
if you are not addicted to money 😉

Besides summer is coming and the weather is great, so it’s good to go outside and move a little, e.g. ride a bike or travel. I’m going to do it and I recommend you to do the same, because it helps to create new ideas and extends our horizons, and after short break you can start to work with motivation and head full of ideas.

[EN] New features in C# 7.0: local functions, ref returns and others

This is the third and the last post about new features in C# 7.0. Today I will focus on:
– local functions
– literal improvements
– ref returns
– few other minor improvements

Local functions

It means we can create local function in a method. I don’t think I will use it often. We can achieve similar effect with Func/Action delegates. Anyway it’s nice to have feature.

Literal imporvements

We can write numbers with separator _ to improve readability or use binary literals to specify bit patterns instead of hexadecimal.

Ref returns

In C# 7.0 we can use ref to return reference to the specific thing, e.g. get reference to item number 1 from an array and store this reference in local variable. I think it can be helpful mostly for game developers for passing ref to big data structures.

Few other improvements

In C# 7.0 we get more improvements. I just want to list them shortly.
– Async methods can return other types than void, Task and Task<T>,
– we can use expression bodies in more places, e.g. accessors, constructors, finalizers. We can create constructor like this

– we can throw an exception in an expression

That’s all new features that we can use in C# 7.0. Hope you use it well 😉

[EN] New features in C# 7.0: Tuples

In the previous post I wrote about out variables and pattern matching in C# 7.0. Today I will focus on another features which are Tuples.

Tuple is not new thing, we have it already in C#, but this time the newest version of C# adds tuple types and tuple literals. With C# 7.0 we can implement method looks like this

GetValues method returns tuple object that contains three fields. Let’s take a look at example

As you can see in GetValues1 method I didn’t specified names for fields, so to get value we need to use default names like Item1, Item2, …, ItemN. We can change it and add our own names for fields. Take a look at the second example of method – GetValues2. In this method I specified field names: Val1, Val2, Val3. When we use this tuple return type we have a hint from IntelliSense with our field names. Item1, Item2, Item3 fields aren’t visible, but we can use it as well and it works.

1

In addition we can assign tuple return type to new local variables, it’s called deconstructing declaration.

If we want to assign result to existing variables we can do it as well.

It’s also good to mention that if you don’t use the latest .NET Framework, but you want to use the newest Tuples, you can do it. Just install the right package from NuGet Packages – System.ValueTuple.

[EN] New features in C# 7.0: out variables, pattern matching

Some time ago I wrote about new features in C# 6.0 and now it’s time to look at the features in C# 7.0 and what news it introduces. In this post I want to focus on out variables and pattern matching.

Out variables

In C# 7.0 we can declare a variable at the point it is passed as an out argument. I have created OutVariables class which contains sample methods implementation to demonstrate how out variables work. To have better view what it simplifies here we have two methods, one is in C# 6.0 (Cs6Style) and the second one is with C# 7.0 (Cs7Style).

Pattern matching

Pattern matching is another feature. In C# 7.0 we can use patterns only in is expressions and in case clausules for now, but it will be extended in the future versions of C#. Let’s take a look at the samples below.

Here we have SampleClass and two methods. Cs7Is method presents how to use is pattern and Cs7Case method presents how to use case pattern.
As you can see using is pattern is similar to the out variables, we can declare variable in the expression and use it later.
Case pattern allows us to extend switch statement. We can switch on any type, not only primitives. We can use patterns in case clausules and these clausules can have additional conditions.
That’s it for today, in the next posts we will take a look at the other features in C# 7.0.