valuetuple Questions

5

Solved

I have a use case where I need to check if a value is a C# 7 ValueTuple, and if so, loop through each of the items. I tried checking with obj is ValueTuple and obj is (object, object) but both of t...
Nonresistance asked 12/10, 2017 at 10:40

3

Solved

Let's say I have a method foo which returns a ValueTuple where one of it's members is disposable, for example (IDisposable, int). What is the best way to make sure the returned disposable object i...
Coccidiosis asked 26/9, 2017 at 12:21

3

Solved

Microsoft's documentation for the out parameter modifier points out the following: Declaring a method with out arguments is a classic workaround to return multiple values. Consider value tup...
Juliajulian asked 15/10, 2022 at 21:2

22

Solved

I've got a VS2017 project that compiles to a DLL which is then called by an EXE written by someone else. Both projects target .Net Framework 4.6.2. I rewrote one of my DLL methods to return a tuple...
Orth asked 17/3, 2017 at 21:33

2

Solved

I am using C# 8.0 with NullableContextOptions (Nullable Reference) enabled. I have a function with this signature: public static (int line, string content)? GetNextNonEmptyLineDown(this IList<...
Gerek asked 2/3, 2019 at 18:23

3

Is there a saner way to do the following: public static class ValueTupleAdditions { public static IEnumerable<object> ToEnumerable<A, B>(this ValueTuple<A, B> tuple) { yield re...
Strander asked 16/5, 2017 at 16:35

5

Solved

How to check if a System.ValueTuple is default? Rough example: (string foo, string bar) MyMethod() => default; // Later var result = MyMethod(); if (result is default){ } // doesnt work I ca...
Emee asked 30/4, 2018 at 12:35

11

Solved

Before Tuples, I used to create a class and its variables, then create object from this class and make that object the return type for some functions. Now, with tuples, I can do the same thing, and...
Arawak asked 20/6, 2017 at 10:33

1

Solved

I consider updating my System.ValueTuple references from 4.4.0 to (current) 4.5.0. To avoid regressions, I'd like to find out what changed between those two releases. The nuget page says: Relea...
Cloutier asked 4/9, 2018 at 12:47

4

I'm trying to deserialize [{"foo": "1", "bar": false}, {"foo": "2", "bar": false}] into List<(string, bool)> type: JsonConvert.DeserializeObject<List<(string foo, bool bar)>>(js...
Intrauterine asked 29/11, 2019 at 10:26

2

Solved

If we do var (hello, world) = GetHelloAndWorldStrings(); if (hello == "hello" && world == "world") Environment.Exit(0); Does that incur any additional costs than just ...
Raines asked 19/8, 2020 at 7:41

1

Solved

I am trying to specify nUnit testCases using tuples, but I get a compiler error in VisualStudio. This simple example demonstrates what I am trying to do: [TestCase((1, 2), (3, 5))] public void ...
Utterance asked 20/5, 2020 at 10:31

1

Solved

If using .Net < 4.7 tuples are not supported. If I install the NuGet "System.ValueTuple", I'm able to write code like public static (string Name, int Age) GetFoo() { return ("Bar", 99)...
Handtohand asked 3/3, 2020 at 14:41

1

Solved

This compiles correctly in C# 7.3 (Framework 4.8): (string, string) s = ("a", "b"); (object, string) o = s; I know that this is syntactic sugar for the following, which also compiles correctly: ...
Caviness asked 19/12, 2019 at 14:7

4

Solved

Is it possible to create a list of ValueTuple in C# 7? like this: List<(int example, string descrpt)> Method() { return Something; }
Kamat asked 29/5, 2017 at 21:25

1

Solved

I'm using web api. I've been a bit lazy and decided to return a value tuple from my controller. [HttpGet] [Route(AuthAPIRoutes.GET_MFA_DEVICES)] public (string Type, string Value)[] GetMultiFactor...
Cytolysin asked 17/6, 2019 at 19:27

1

Solved

I am trying to check if an object variable is (int, int) and if so I will use the casted variable so I have tried the codes below: //this one gives the error public void MyMethodWithIs(object val)...
Reorganization asked 12/5, 2019 at 20:22

1

Solved

ValueTuple types, declared as fields, can be mutable: class Foo { (int, int) bar = (0, 1); } or readonly: class Foo { readonly (int, int) bar = (0, 1); } and this (im)mutability applies to ...
Mackinaw asked 21/4, 2019 at 20:10

3

Solved

While trying to serialize a named value tuple to JSON string, it loses the names assigned to items (string type, string text) myTypes = ("A", "I am an animal"); var cnvValue = JsonConvert.Serializ...
Curren asked 28/1, 2019 at 8:20

2

Solved

I'm thinking this could be a convenient dictionary: var myDict = new Dictionary<(int, int), bool>(); What would the hashes look like? What would the equivalent key type (struct) look like?...
Murillo asked 18/12, 2018 at 10:31

1

Solved

I'm finding that ValueTuples evaluate differently when I access their properties from a collection. public static List<Tuple<string, bool>> MyTupleList = new List<Tuple<string, ...
Liverwurst asked 4/12, 2018 at 12:50

2

Solved

When I am trying to compile the following code: var post = iPostService.GetAll().Select(x => (x.Title, x.Author)); I get the compiler error: 'An expression tree may not contain a tuple litera...

4

Solved

Is it possible to use value tuples as model type in views in ASP.NET Core MVC? I mean like this: Controller: public IActionResult Index() { ... (int ImportsCount, int ExportsCount) importsExpo...
Bobbobb asked 31/5, 2017 at 14:23

1

Solved

I have a interface in C# with method with this return type: Task<(Guid, int)?> I need to implement this interface in F# and if I am not mistaken this should be equivalent in F#: Task<N...
Organize asked 19/6, 2018 at 17:52

1

Solved

With ValueTuple in C# 7, it is now possible to write methods and properties that return or consume composite objects without explicitly declaring a type. These named tuples can however be potential...
Tello asked 6/5, 2018 at 9:47

© 2022 - 2024 — McMap. All rights reserved.