Join us in building a kind, collaborative learning community via our updatedCode of Conduct.

Questions tagged [c#-7.0]

The versions of C#, released in 2017 that adds value tuples, local functions, basic pattern matching, ref locals and returns, async main and various other new features.

0
votes
0answers
11 views

Retrieving connection string in integration test

I am trying to do some integration tests for my asp.net Core 2.1 project.I initialise on startup file my connection string but when i run the test it still empty in handler, what is wrong on my code?...
0
votes
1answer
48 views

What is the purpose of Deconstruct method in KeyValuePair<> struct?

I was looking at System.Collections.Generic.KeyValuePair<TKey, TValue> struct in System.Runtime, Version=4.2.1.0 and this method took my attention.Here's the signature:public void ...
0
votes
0answers
89 views

why can't we use re-throw with the ternary operator?

In C#7 we can write this: var a=1 < 2 ? "true" : throw new Exception();why can't we to do rethrowing? For example: try{var er=1/0;}catch (Exception ex){var a=ex....
12
votes
4answers
212 views

What are single and zero element tuples good for?

C# 7.0 introduced value tuples and also some language level support for them. They added the support of single and zero element tuples as well; however, I could not find out any scenario when they ...
-1
votes
0answers
41 views

AspNetCore.SignalR.Client Send - why async?

SignalR client send methods in AspNetCore.SignalR.Client are all async, however they do not wait for a result and as far as I understand are fire and forget.Why is Send async ?Is it ok not to ...
-2
votes
0answers
31 views

How to replace syntaxes from dictionary to tuple list in files c# 7.0

We have over 50-100 views and is there a way to quickly replace this syntax without modifying anything else?They all start with var crumbs=new Dictionary()From:var crumbs=new Dictionary<...
4
votes
0answers
58 views

With C# 7.x syntax additions, is there a version of “x ?? (x=MakeX())”, where x is assigned via an out parameter?

One idiom in C# to 'create a value on first access'1 is to use something like the following2:public string X {get {return _x ?? (_x=MakeX());}}Given a slight variation, where ...
-1
votes
1answer
41 views

How to make a seperate function to print output in C#?

I am learning function's in C# & decided to make a calculator. Here is the code I have written:-using System;namespace Second_Project{class Program{...
1
vote
1answer
46 views

Compiler throws exception for same code in different PC

Line below in my VS and works fine I checked in and my colleague get these code piece..vm.MuayeneId=(MuayeneId ?? SessionItems.AktifMuayene?.MuayeneId) ?? throw new Exception("Muayene Id ...
0
votes
2answers
78 views

C# Immutable HashSet locking

suppose a server storing an ImmutableHashSet of connection dataImmutableHashSet<ConnectionData> connections=new ...I then have various calls adding/removing/reading from this, ie:...
0
votes
1answer
36 views

What is the difference between attributes (properties) of OUt and Ref Keyword in C#? [duplicate]

What is the difference between attributes (properties) of OUt and Ref Keyword in C#?.Do these Keywords belong to the C# new features?.Can anyone tell me the difference between the functionality of OUT ...
-1
votes
1answer
66 views

Automatic properties compiler error

Writing a simple class in c# comes up with error "Not all code path return a value"public class Genre{private string _name;public string Name{get=> _name;set=&...
2
votes
1answer
50 views

ReferenceEquals on struct after C#7

Since C# 7.2 it is possible to use the "ref" keyword on structs to create embedded references. How can I determine if two struct variables are pointing to the same reference? ReferenceEquals always ...
0
votes
2answers
101 views

Null coalescing Operator on DateTime c#

I personally like the null coalescing Operator and I try to use it in my getters. But it seems to be restricted to certain Datatypes. For Instance following isn't building:public DateTime From=>...
3
votes
1answer
74 views

c# struct with no reference types

Consider a struct which does not contain any reference fields (only basic types and other structs).Consider this struct will be used in collections and I want it to behave like a value type (ie int)....
0
votes
2answers
88 views

Extension method to compare all fields including IEnumerable

I am trying to write an extension method that compares objects based on their fields.I have this:public static class MyExtensions {public static bool FieldsEquals(this object o, object other)...
1
vote
1answer
218 views

repeatedly calling HashCode.Combine

Is it correct to repeatedly call HashCode.Combine ?I am trying to create a general extension method to produce an object hashcode from combining the hashcodes of all its properties like this:using ...
-2
votes
2answers
79 views

C#7 Out Variables with Tuples

Is it possible to use the C#7 feature of out variables when the out variables is a Tuple?The exact scenario I have is this:private readonly Dictionary<int, (bool, DateTime)> _dictionary;...
0
votes
1answer
85 views

Json.NET constructing JSON with object initializers

I want to construct Json.NET object using object initializers for collections.I can do:JObject jsonObject=new JObject { { "Date", DateTime.Now }, { "obj", new JObject { { "string", "bla" } } } };...
0
votes
2answers
79 views

json.net serialize derived as generic base

(this issue stems from trying to serialize/deserialize LikeType classes to JSON - https://github.com/kleinwareio/LikeType)I have:public abstract class LikeType<T>{public T ...
0
votes
2answers
51 views

Why doesn't C# VS2017 intellisense work with var and local functions?

Why doesn't Intellisense work if I do something like this.It does work though if I explicitly declare Foo
0
votes
1answer
86 views

Unable to build while using C# 7.0 features

Recently I pulled latest code on a project which compiles fine for some co-workers, but not for me. There is a simple line in the code that causes it not to build:if (x is null || y is null)...
0
votes
1answer
79 views

C# Nested ConcurrentDictionary wrapper

There seem to be no way to nest ConcurrentDictionary so that they share one lockI am trying to create a class that will wrap a 3-deep nested dictionary with a lockSo that I can do NestedDict[k1][...
0
votes
1answer
15 views

How to reatart depend service if the main aervice failed and recovered in topshelf

I am having windows service which created using topshelf. Sometime this service get stopped. So i want it be automatically restarted. So we are having a onrecovery option in topshelf. Now my ...
2
votes
3answers
150 views

Local functions and SOLID principles C#

I know that starting from C# 7.0 we are able to create local functions, but how is this related with the SOLID principles to achieve a good design model? I mean, doesn't this break the Single ...
-3
votes
1answer
103 views

Errors when using the C# 7.0 Tuple in a method

I am trying the new Tuple syntax in C# 7.0 using the code below and it's not compiling. VS 2017 15.7 .Net 4.6 doesn't give an error count but shows the errors in the output window. Resharper doesn't ...
0
votes
0answers
37 views

How to generate a secure link with the client information ASP.net Core 2

In my application i have to create a company. The company has the different user. When the company is created in the system. I wanted to generate a secure link for the company. When the user comes ...
1
vote
4answers
83 views

Is there any point in using local functions if to only use them once?

Imagine I have this code:public void Foo(){// Do bar work// Do baz work// Do foobar work}And I realize I can (and should because it was doing more than one thing) refactor it into:...
5
votes
1answer
111 views

Performance of assigning a simple lambda expression or a local function to a delegate

When using a very simple expression as key to create an ILookup with Enumerable.ToLookup<TSource, TKey> Method (IEnumerable<TSource>, Func<TSource, TKey>) I can use a lambda ...
3
votes
1answer
66 views

What are the differences between C# Local Functions vs JavaScript Nested Functions?

In C#, a Local Function is such: public int MyFunction(int parameter){int local=6;return MyLocalFunction(4);// Local Functionint MyLocalFunction(int ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,