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 8407965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:31:03+00:00 2026-06-09T23:31:03+00:00

I am making extensive use of dictionaries to decouple some (highly coupled) code. Here

  • 0

I am making extensive use of dictionaries to decouple some (highly coupled) code. Here are the relevant ones for my question:

//Output table
System.Data.DataTable dtOutput = new System.Data.DataTable();
dtOutput.Columns.Add("Ticket", typeof(string));
dtOutput.Columns.Add("Transit", typeof(string));
dtOutput.Columns.Add("City", typeof(string));
dtOutput.Columns.Add("Province", typeof(string));
dtOutput.Columns.Add("Outage Start Time", typeof(DateTime));
dtOutput.Columns.Add("Outage End Time", typeof(DateTime));
dtOutput.Columns.Add("Priority", typeof(string));
dtOutput.Columns.Add("Business Impact", typeof(TimeSpan));
dtOutput.Columns.Add("Time To Repair (mins)", typeof(Double));
dtOutput.Columns.Add("Summary", typeof(string));

Dictionary<string, int> outputColumnsLegend = new Dictionary<string, int>();
foreach (DataColumn col in dtOutput.Columns)
{
    outputColumnsLegend.Add(col.ColumnName, dtOutput.Columns.IndexOf(col) + 1);
}

Dictionary<string, Variable> outputVariable = new Dictionary<string, Variable>()
{
    {"Ticket", new Variable()},
    {"Transit", new Variable()},
    {"City", new Variable()},
    {"Province", new Variable()},
    {"Outage Start Time", new Variable()},
    {"Outage End Time", new Variable()},
    {"Priority", new Variable()},
    {"Business Impact", new Variable()},
    {"Time To Repair (mins)", new Variable()},
    {"Summary", new Variable()}
};

where Variable is simply:

public class Variable
{
    public object Value { get; set; }
}

Now, to create the output table I am trying to use:

DataRow dataRow = dtOutput.NewRow();
foreach (DataColumn col in dtOutput.Columns)
{
    dataRow[outputColumnsLegend[col.ColumnName]] = (col.DataType)outputVariable[col.ColumnName].Value;
}

However, the reference to col in col.DataType causes this error:

The type or namespace 'col' could not be found (are you missing a using directive or an assembly reference?)

I’m not sure why I am throwing this error or how to fix it. Also, I am not sure if col.DataType should be col.GetType instead (assuming this can be made to work).

Any advice is appreciated.

Regards.

  • 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-06-09T23:31:05+00:00Added an answer on June 9, 2026 at 11:31 pm

    There’s no net result to this code.
    Because a DataTable stores data as objects (which is why you have to cast when getting data out of them) and since your Variable() class holds an object, no amount of casting is actually going to do any useful work.

    Basically, you’re unboxing and then immediately re-boxing the data on the same line, even if the cast were made to work.

    If you want to preserve types at runtime to avoid this (which is what it seems like you might be trying to do), then you need to make your variable class a generic class like so:

    public class Variable<T>
    {
       public T Value {get; set;}
    }
    

    You would then instantiate specific types of Variable, such as:

    Variable<int> someInt;
    Variable<string> someString;
    etc.
    

    However, even if you do this, you’ll still be boxing back as an object the second you place it in a DataTable, so it’s an exercise in futility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making extensive use of boost:shared_ptr in my code. In fact, most of
I'm making extensive use of Markdown in a new project that I'm working on,
I have a HashSet<string> that is instantiated using StringComparer.CurrentCultureIgnoreCase and am making extensive use
A website that I'm working on is making extensive use of the HttpContext.Current.Application store
I make extensive use of multiline docstrings in my python source code to include
I am making extensive use of stl vectors to manage memory (de-) allocation of
I am making use of jQuery's .autocomplete plugin, and I would appreciate some assistance
We are making extensive use of LessCss and and jQueryUI in a current project
I have been making extensive use of XMLHttpRequests and JSON to fetch from a
I am making a top-down shooter that makes extensive use of TMX maps created

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.