CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2010
    Posts
    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

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    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
  •  





Click Here to Expand Forum to Full Width

Featured