-
July 7th, 2010, 06:44 AM
#1
Implicitly-typed error
hey guys
when compiling this code it gave me an error
"Implicitly-typed local variables must be initialized"
how to avoid the error?
.net 3.5
var q;
decimal tot;
if (Type == "all")
{
......... code
q = from us in DBInstance.GetDBInstance.Accounts
orderby us.ID
select new { ID = us.ID, Name = us.Name };
tot = 0M;
foreach (var item in q)
{
.......
}
return t;
}
.........
q = from us in DBInstance.GetDBInstance.Accounts
where us.Type == Type
orderby us.ID
select new { ID = us.ID, Name = us.Name };
tot = 0M;
foreach (var item in q)
.......
thanks
-
July 7th, 2010, 01:07 PM
#2
Re: Implicitly-typed error
Seems obvious, no? The compiler needs to know what type to assign to 'q', but you don't tell it what 'q' is until later. So, just declare q properly (i.e., whatever is being returned by the statement below).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|