I hate technical books that try to sound young...
-
Uhm I am confused, there are no anonymous types used in either code snippet! :confused:
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
I'm guessing he meant the
var
keyword.Regards Senthil _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
Technically the use of "var" in the first example makes it an anonymous type, albeit a simplistic one. Cr@p example though.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
OriginalGriff wrote:
Technically the use of "var" in the first example makes it an anonymous type, albeit a simplistic one.
Well in this case the var is just an implicitly typed shortcut and the type is known at compile time. I would not call this an anonymous type at all. But I get what you mean.
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
I'm guessing he meant the
var
keyword.Regards Senthil _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
Yeah, apparently. But if the book used that snippet as an example of an anonymous type, that's quite concerning in my opinion :-)
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
Technically the use of "var" in the first example makes it an anonymous type, albeit a simplistic one. Cr@p example though.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
OriginalGriff wrote:
Technically the use of "var" in the first example makes it an anonymous type
Nope. It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code compiles. A var need not always be neccesarily attached with annonymous types. E.g.
string[] words = { "apple", "strawberry", "grape", "peach", "banana" };
var wordQuery = from word in words
where word[0] == 'g'
select word;Here we already know wordQuery is going to be of type IEnumerable and var need not be used.
IEnumerable
wordQuery will work just as well. 1. Apologies for posting code here but I could'nt help it. 2. Thanks for making me do some reading on this. 3. As Nish said, I see what you mean here. But I had to post this, I had to. :) -
OriginalGriff wrote:
Technically the use of "var" in the first example makes it an anonymous type
Nope. It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code compiles. A var need not always be neccesarily attached with annonymous types. E.g.
string[] words = { "apple", "strawberry", "grape", "peach", "banana" };
var wordQuery = from word in words
where word[0] == 'g'
select word;Here we already know wordQuery is going to be of type IEnumerable and var need not be used.
IEnumerable
wordQuery will work just as well. 1. Apologies for posting code here but I could'nt help it. 2. Thanks for making me do some reading on this. 3. As Nish said, I see what you mean here. But I had to post this, I had to. :)Abhinav S wrote:
It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code exectues.
That's not fully correct. The variable type is known at compile time. It just saves you some typing :-)
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
OriginalGriff wrote:
Technically the use of "var" in the first example makes it an anonymous type
Nope. It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code compiles. A var need not always be neccesarily attached with annonymous types. E.g.
string[] words = { "apple", "strawberry", "grape", "peach", "banana" };
var wordQuery = from word in words
where word[0] == 'g'
select word;Here we already know wordQuery is going to be of type IEnumerable and var need not be used.
IEnumerable
wordQuery will work just as well. 1. Apologies for posting code here but I could'nt help it. 2. Thanks for making me do some reading on this. 3. As Nish said, I see what you mean here. But I had to post this, I had to. :)Abhinav S wrote:
the variable knows nothing about what it will be until the code exectues.
Well actually, the type is resolved at compile time. At runtime, there is no difference between explicit and implicit typing.
Regards Senthil _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
OriginalGriff wrote:
Technically the use of "var" in the first example makes it an anonymous type
Nope. It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code compiles. A var need not always be neccesarily attached with annonymous types. E.g.
string[] words = { "apple", "strawberry", "grape", "peach", "banana" };
var wordQuery = from word in words
where word[0] == 'g'
select word;Here we already know wordQuery is going to be of type IEnumerable and var need not be used.
IEnumerable
wordQuery will work just as well. 1. Apologies for posting code here but I could'nt help it. 2. Thanks for making me do some reading on this. 3. As Nish said, I see what you mean here. But I had to post this, I had to. :)Just because Griff MkI posts codes, there's no need to carry on the crime. Anyone would think this is a techn... ... oh, the shame, this is a technical site.
Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
-
Just because Griff MkI posts codes, there's no need to carry on the crime. Anyone would think this is a techn... ... oh, the shame, this is a technical site.
Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
Nagy Vilmos wrote:
... oh, the shame, this is a technical site.
:laugh:
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
OriginalGriff wrote:
Technically the use of "var" in the first example makes it an anonymous type
Nope. It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code compiles. A var need not always be neccesarily attached with annonymous types. E.g.
string[] words = { "apple", "strawberry", "grape", "peach", "banana" };
var wordQuery = from word in words
where word[0] == 'g'
select word;Here we already know wordQuery is going to be of type IEnumerable and var need not be used.
IEnumerable
wordQuery will work just as well. 1. Apologies for posting code here but I could'nt help it. 2. Thanks for making me do some reading on this. 3. As Nish said, I see what you mean here. But I had to post this, I had to. :):thumbsup: 5! I'm always open to correction. Especially when its stuff I'm trying to learn. Think I'll keep looking for a rather more accurate book. :sigh:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
-
Abhinav S wrote:
It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code exectues.
That's not fully correct. The variable type is known at compile time. It just saves you some typing :-)
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
Fixed! :)
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
-
:thumbsup: 5! I'm always open to correction. Especially when its stuff I'm trying to learn. Think I'll keep looking for a rather more accurate book. :sigh:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
OriginalGriff wrote:
I'm always open to correction.
Abhinav was not 100% right. Please read the corrections to his correction too :-)
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
Fixed! :)
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
Thank you.
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
:thumbsup: 5! I'm always open to correction. Especially when its stuff I'm trying to learn. Think I'll keep looking for a rather more accurate book. :sigh:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
Well he fixed his post, so it's all good now :-)
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
OriginalGriff wrote:
I'm always open to correction.
Abhinav was not 100% right. Please read the corrections to his correction too :-)
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
Nishant Sivakumar wrote:
Abhinav was not 100% right. Please read the corrections to his correction too
I need a beer... :)
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
-
Nishant Sivakumar wrote:
Abhinav was not 100% right. Please read the corrections to his correction too
I need a beer... :)
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
Thanks again for fixing it :-) You don't want newbies who may encounter it in future to go away with wrong info. Good work! :thumbsup:
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
Thanks again for fixing it :-) You don't want newbies who may encounter it in future to go away with wrong info. Good work! :thumbsup:
Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
Nishant Sivakumar wrote:
You don't want newbies who may encounter it in future to go away with wrong info
Good point.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
-
Nishant Sivakumar wrote:
Abhinav was not 100% right. Please read the corrections to his correction too
I need a beer... :)
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
Abhinav S wrote:
I need a beer...
...again. It is rude to stop at one, the others may think you don't like them.
Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
-
I decided it was time I read up on LINQ: never really used it, time I learnt. So, I have a quick look for a book. Amazon: Sams LINQ Unleashed for C#. Lets have a quick look "Surprise me" "check out Wikipedia; Wikipedia is wicked cool at providing detailed facts" Hmmm. Wicked cool? And a code fragment to illustrate how wonderfull anonymous types are:
var request = HttpWebRequest.Create(string.Format(url, stock)); using (var response = request.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { return (reader.ReadToEnd()); } }
I hate that. Why use an example where it is actually clearer if you don't use anonymous types?
WebRequest request = HttpWebRequest.Create(string.Format(url, stock)); using (WebResponse response = request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { return (reader.ReadToEnd()); } }
Don't think I'll buy that one...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
It's not the 'wicked cool' that throws me in that statement it the 'detailed facts' Wikipedia is convenient, but not to be relied upon too heavily.
My current favourite phrase: I've seen better!
-SK Genius
-
Abhinav S wrote:
I need a beer...
...again. It is rude to stop at one, the others may think you don't like them.
Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
-
I decided it was time I read up on LINQ: never really used it, time I learnt. So, I have a quick look for a book. Amazon: Sams LINQ Unleashed for C#. Lets have a quick look "Surprise me" "check out Wikipedia; Wikipedia is wicked cool at providing detailed facts" Hmmm. Wicked cool? And a code fragment to illustrate how wonderfull anonymous types are:
var request = HttpWebRequest.Create(string.Format(url, stock)); using (var response = request.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { return (reader.ReadToEnd()); } }
I hate that. Why use an example where it is actually clearer if you don't use anonymous types?
WebRequest request = HttpWebRequest.Create(string.Format(url, stock)); using (WebResponse response = request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { return (reader.ReadToEnd()); } }
Don't think I'll buy that one...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
sorry, but type inference makes code clearer, I like the first version better. Why should I have to redeclare the variable's type when
new
ing it? It's easily inferred from the right-side.var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)
is better than
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams "Let me get this straight. You know her. She knows you. But she wants to eat him. And everybody's okay with this?"