Answered by:
declaring a ? in advance to facilitate if

Question
-
User379720387 posted
Sorry, don't know what the name is.
This is my code.
var cshoeinfo = (from cs in client.ClientShoes where cs.ProviderId == providerid select cs).FirstOrDefault());
Now I need to put it inside an if statement, how do I declare this?
I am used to doing this:
IENumerable<dynamic> cshoeinfo;
This causes "cannot covert type 'ClientShoe to Systems.Collection.Generic.dynamic."
Saturday, October 10, 2015 11:18 PM
Answers
-
User-821857111 posted
ClientShoe cshoeinfo = null; if(blah blah) { cshoinfo = client.ClientShoes.FirstOrDefault(cs => cs.ProviderId == providerid); }
Note: I have used method syntax for the query. You can use your version which is query syntax. The result is the same.
https://msdn.microsoft.com/en-us/library/bb397947.aspx
Another note, if you are unsure that type your LINQ query returns, hover over the var keyword in VS, It will tell you.
A final note, the error message also told you what the data type of cshoeinfo actually is.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, October 11, 2015 3:59 PM
All replies
-
User-821857111 posted
ClientShoe cshoeinfo = null; if(blah blah) { cshoinfo = client.ClientShoes.FirstOrDefault(cs => cs.ProviderId == providerid); }
Note: I have used method syntax for the query. You can use your version which is query syntax. The result is the same.
https://msdn.microsoft.com/en-us/library/bb397947.aspx
Another note, if you are unsure that type your LINQ query returns, hover over the var keyword in VS, It will tell you.
A final note, the error message also told you what the data type of cshoeinfo actually is.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, October 11, 2015 3:59 PM -
User379720387 posted
It said class.
Thanks.
Sunday, October 11, 2015 9:58 PM -
User-821857111 posted
It should also have said ClientShoe.
Is your issue still unresolved?
Monday, October 12, 2015 2:01 AM -
User379720387 posted
Nope.
Must have hit 'mark as answer" twice.
Monday, October 12, 2015 7:48 AM