Posts

Showing posts with the label Potential Features

C# 7.0 Potential Features – Local Functions

Image
Thoughts on C# 7.0 Local Functions. Potential Features - Local Functions Frankly, when I first tried this, I thought that it's just a nice and compact way of defining local helpers. In fact, it's much more interesting and useful feature. Today I'm going to explore and explain it in more details. Let's  start with a brief overview of the current situation. Before Local Functions Private methods The first option that existed in C# 1 is having a private method. That’s a clean and simple solution. It has few issues, though. PrintMe might have no sense outside of ThatTime method, but it’s accessible for every other method inside the class. It will be taken into account by IntelliSense. Func and Action We can try to hide our helper inside the scope of ThatTime method by converting it to Func<int, string>: Any disadvantages ?? Yep, a lot. The call is unnecessary expensive: it will produce  more all

C# 7.0 Potential Features – Tuples

Image
In this article, let's discuss on Tuple Class in C# and the potential new proposals that are being considered for C#7. Potential Features - Tuple What is Tuple in C#? Basically, a  tuple  ( Tuple in C# ) is an ordered sequence, immutable, fixed-size and of heterogeneous objects, i.e., each object being of a specific type. The  tuples  are not new in programming. They are already used in F#, Python, and databases. A tuple allows you to combine multiple values of possibly different types into a single object without having to create a custom class. This can be useful if you want to write a method that for example returns three related values but you don’t want to create a new class. System.Tuples namespace supports Tuple class in C#. The purpose of a tuple is to create a way to return multiple values from a function. class CodeYourWayTupleDemo { static void Main() { // Create three-item tuple. Tuple tuple = new Tuple (10, "Code