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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:21:32+00:00 2026-06-05T08:21:32+00:00

Hypothetically it’d be handy for me to do this: foo.GetColumnValues(dm.mainColumn, int) foo.GetColumnValues(dm.mainColumn, string) where

  • 0

Hypothetically it’d be handy for me to do this:

foo.GetColumnValues(dm.mainColumn, int)
foo.GetColumnValues(dm.mainColumn, string)

where the GetColumns method will call a different method inside depending on the type passed.

Yes, I could do it as a boolean flag or similar, I just wondered if there was a way to perhaps pass this, and then ask:

typeof(arg[1]) or similar…

I could also override the method, use generics, etc – I know there are different ways to do this, I was just curious if this was possible.

  • 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-05T08:21:33+00:00Added an answer on June 5, 2026 at 8:21 am

    There are two common approaches. First, you can pass System.Type

    object GetColumnValue(string columnName, Type type)
    {
        // Here, you can check specific types, as needed:
    
        if (type == typeof(int)) { // ...
    

    This would be called like: int val = (int)GetColumnValue(columnName, typeof(int));

    The other option would be to use generics:

    T GetColumnValue<T>(string columnName)
    {
        // If you need the type, you can use typeof(T)...
    

    This has the advantage of avoiding the boxing and providing some type safety, and would be called like: int val = GetColumnValue<int>(columnName);

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

Sidebar

Related Questions

This is question is about whether this will hypothetically work for a project I'm
Hypothetically -- not that I did this -- let's say someone I know updated
Let's say, hypothetically (read: I don't think I actually need this, but I am
I have a collected named foo hypothetically. Each instance of foo has a field
Let's say hypothetically I want to replace all 'a' in a string with 'b'
Hypothetically, in a SQL Server database, if I have a table with two int
string str1 = 12345ABC...\\...ABC100000; // Hypothetically huge string of 100000 + Unicode Chars str1
I have two tables named foo and bar , hypothetically speaking. foo has columns
My problem is this: Say I hypothetically have a table called fastfood which has
So I'll try and play devil's advocate on this one... Hypothetically there is a

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.