method-group Questions

3

Solved

Consider void Main() { var list = new[] {"1", "2", "3"}; list.Sum(GetValue); //error CS0121 list.Sum(s => GetValue(s)); //works ! } double GetValue(string s) { double val; double.TryParse...
Wishywashy asked 12/10, 2011 at 20:3

3

Solved

I'm trying to figure out of if there is a simple syntax for converting a Method Group to an expression. It seems easy enough with lambdas, but it doesn't translate to methods: Given public delega...
Britten asked 16/6, 2009 at 21:54

6

Solved

Getting the error Cannot Assign "AppendText" because it is a "method group". public partial class Form1 : Form { String text = ""; public Form1() { InitializeCo...
Budwig asked 4/11, 2013 at 16:39

1

Solved

I started to use the method group syntax a couple of years ago based on some suggestion from ReSharper and recently I gave a try to ClrHeapAllocationAnalyzer and it flagged every location where I w...
Gesner asked 8/11, 2018 at 13:14

4

Solved

In a project I'm currently working on, we have many static Expressions that we have to bring in local scope with a variable when we call the Invoke method on them and pass our lambda expressions' a...
Bazil asked 15/2, 2016 at 22:53

3

Solved

I have an extension method like public static void RemoveDetail<TMaster, TChild>(this TMaster master, TChild child) where TMaster : class, IMaster<TChild> where TChild : class, IDeta...
Mahoney asked 2/9, 2015 at 10:14

1

Why can't the correct overload to be called be inferred on the line marked // Compiler Error in the code below when the type is correctly inferred in all the other cases? public static class Code ...
Cyme asked 3/7, 2014 at 22:26

5

Solved

I have often encountered an error such as "cannot convert from 'method group' to 'string'" in cases like: var list = new List<string>(); // ... snip list.Add(someObject.ToString); of cour...
Tallyho asked 20/5, 2009 at 8:31

1

Solved

James Michael Hare recently wrote a blog post about Char static methods. He talks about using a method group to write less-wordy LINQ: if (myString.Any(c => char.IsLower(c))) { xyzzy(); } if (m...
Arboriculture asked 9/10, 2012 at 15:55

4

In code below I must declare method MdrResponseInterpreter static otherwise I have compilation error. class.... { private StandardBuilder _mdrResponseBuilder = new StandardBuilder(MdrResponseI...
Shoon asked 28/3, 2012 at 9:17

2

Solved

While updating my UI code (C# in a .NET 4.0 application), I ran into a strange crash due to a call to the UI being executed in the wrong thread. However, I was invoking that call on the main thread...
Burglarious asked 30/11, 2011 at 16:5

2

Solved

Code before the changes: List<ProductBrandModel> model = brands.Select(item => Mapper.Map<ProductBrand, ProductBrandModel>(item)).ToList(); Code after the improvement: List<...
Nikko asked 24/8, 2011 at 20:55

3

Solved

What's the difference between Class1.Method1<Guid, BECustomer>("cId", Facade.Customers.GetSingle); and Class1.Method1<Guid, BECustomer>("cId", x => Facade.Customers.GetSingle(x...
Accelerometer asked 12/7, 2011 at 10:10

2

Solved

The following call to the overloaded Enumerable.Select method: var itemOnlyOneTuples = "test".Select<char, Tuple<char>>(Tuple.Create); fails with an ambiguity error (namespaces remov...
Clown asked 5/3, 2011 at 12:25

2

Solved

I discovered something very strange that I'm hoping to better understand. var all = new List<int[]>{ new int[]{1,2,3}, new int[]{4,5,6}, new int[]{7,8,9} }; all.ForEach(n => n.ForEac...
Laky asked 9/2, 2010 at 16:4

2

Solved

I have created the following function: public void DelegatedCall(Action<Object> delegatedMethod) And defined the following method public void foo1(String str) { } However, when I try to...
Pagoda asked 16/1, 2011 at 9:55

7

Solved

When dealing with something like a List<string> you can write the following: list.ForEach(x => Console.WriteLine(x)); or you can use a method group to do the same operation: list.ForEa...
Bellona asked 1/10, 2010 at 18:20

2

Solved

I'm interesting in some design choices of C# language. There is a rule in C# spec that allows to use method groups as the expressions of is operator: class Foo { static void Main() { if (Main is...
Honduras asked 12/7, 2010 at 20:7
1

© 2022 - 2024 — McMap. All rights reserved.