Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:31:59+00:00 2026-05-22T15:31:59+00:00

I am developing a library that initializes plain-old data objects from data retrieved from

  • 0

I am developing a library that initializes plain-old data objects from data retrieved from SQL Server stored procedures. One of its methods is the following one:

public static T RetrieveCompound<T, U>(string cmdText, params Parameter[] parameters)
    where T : Header<U>, new()
    where U : class, new() {

    Box<T> headerBox = new Box<T>();
    List<U> details;
    Execute(cmdText, parameters, new Action<Row>[] {
        SetReferenceAction<T>(headerBox) +
        delegate(Row row) { details = headerBox.Value.Details; },
        delegate(Row row) { details.Add(row.ToObject<U>()); }
    });
    return headerBox.Value;
}

The third parameter of Execute is an array of Action<Row>s. Although no static analyzer can programmatically prove it, because of the way the Execute method was programmed, no delegate can be run before the ones preceding it in the array. That means that the delegate

delegate(Row row) { details.Add(row.ToObject<U>()); } // use

must necessarily run after the delegate

delegate(Row row) { details = headerBox.Value.Details; } // initialize

And, thus, the variable details will necessarily be initialized before it is used.

But C# still complains: “Use of unassigned variable ‘details’.”

Is there any way to make C# not complain about uninitialized variables that are actually not?


I am beginning to think C# is not for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:32:00+00:00Added an answer on May 22, 2026 at 3:32 pm

    This is the usual workaround:

    List<U> details = null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a library that uses one or more helper executable in the
I am developing a library for Android that requires frequent updates from a central
I am developing a wrapper for a third party function library that is interfacing
I'm developing a Flex 2 application, and I noticed that part of the library
I am developing a library and an application that uses the library in Python
I'm developing a class library that will be used in a number of different
I'm developing a static library that will be distributed to other developers, who may
I am developing a class library that will be used in several projects. In
i'm developing an application that is listening to tcp to get some xml data
I'm developing an iPhone application that uses the iPod library to play some songs.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.