The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jblack1395 (36) [Avatar] Offline
#1
page 130, Func<int, int, int> was not introduced in .NET 2.0
The Func<...> delegate is in .NET 3.5, and I think the example is incorrect. You can use an anonymous function in your example, but it should be changed, IMO.
jon.skeet (483) [Avatar] Offline
#2
Re: page 130, Func&lt;int, int, int&gt; was not introduced in .NET 2.0
Could you specify exactly where on P130 you're talking about? I can see two mentions of Func<,,>:

"We're using a delegate type called Func, which is available in .NET 3.5."

and then on P131, when it talks about anonymous methods,

"C# 2.0 was a big step forward. It added generics, so we could declare generic delegate like Func and use the new anonymous methods feature to create them instead of writing named method:

Func<int, int, int> add = delegate(int a, int b) { return a + b; }

Finally, .NET 3.5 and C# 3.0 came with several other changes. The Func delegate was added to the system libraries and C# added lambda expressions that allow us to write the same code in a much more succinct way:"

That all looks correct to me. Is there another bit you're concerned about?

Jon
jblack1395 (36) [Avatar] Offline
#3
Re: page 130, Func&lt;int, int, int&gt; was not introduced in .NET 2.0
C# 2.0 was a big
step forward. It added generics, so we could declare generic delegate like Func and use
the new anonymous delegates feature to create them instead of writing named method:
Func<int, int, int> add = delegate(int a, int b) { return a + b; }


This is incorrect as it was added in .NET 3.5
http://msdn.microsoft.com/en-us/library/bb549151.aspx

I may need to get a newer version of the book. smilie

I started to read from the beginning in case you made other changes that I had missed.
jon.skeet (483) [Avatar] Offline
#4
Re: page 130, Func&lt;int, int, int&gt; was not introduced in .NET 2.0
That doesn't claim that Func was in .NET 2.0. Just to highlight:

"It added generics, so we could declare generic delegate like Func and use the new anonymous methods feature to create them instead of writing named method"

In other words, any developer can declare the Func<,,> delegate themselves, regardless of whether it's in the framework or not.

Does it sound more reasonable now? Arguably it would be clearer if we used a different delegate name, but then it would be inconsistent when we use Func a lot later on.
jblack1395 (36) [Avatar] Offline
#5
Re: page 130, Func&lt;int, int, int&gt; was not introduced in .NET 2.0
I think it is confusing. Perhaps use a different name, then suggest that Func can also be used.
Tomas Petricek (160) [Avatar] Offline
#6
Re: page 130, Func&lt;int, int, int&gt; was not introduced in .NET 2.0
Hi, yes, it probably sounds a bit confusing, but I'm not sure whether changing the name of the delegate would be the right thing to do - the point is that you really could define a delegate type just like Func from .NET 3.5. I think we could change the sidebar like this (changes highlighted):

It added generics, so we could declare generic delegate like Func and use
the new anonymous methods feature to create them instead of writing named method:

delegate R Func<T1, T2, R>(T1 a, T2 b);
Func<int, int, int> add = delegate(int a, int b) { return a + b; }

Finally, .NET 3.5 and C# 3.0 came with several other changes. The Func delegate was added to the system libraries, so you no longer have to declare it yourself and C# added lambda expressions that allow us to write the same code in a much more succinct way:


Would something like this clarify it?
jblack1395 (36) [Avatar] Offline
#7
Re: page 130, Func&lt;int, int, int&gt; was not introduced in .NET 2.0
Yes, I think that would help out.

Thank you. smilie