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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:11:46+00:00 2026-05-23T12:11:46+00:00

I have a MyFunction that may take several datatypes, which are all very similar.

  • 0

I have a MyFunction that may take several datatypes, which are all very similar. I just want to pass all these different types of data into MyFunction with multithreading and type cast in MyFunction. Is this something possible? Is using dictionary a good idea? Please advise.

Main(){
    Parallel.ForEach(objectType1, MyFunction)
    Parallel.ForEach(objectType2, MyFunction)
    Parallel.ForEach(objectType3, MyFunction)
}

MyFunction(object arg){
  Dictionary<string, object> d = (Dictionary<string, object>) arg;
  Type1 t1;
  Type2 t2;
  Type3 t3;
  if (d.Key == "Type1") {
        t1 = (Type1) d.Value;
        ProcessType1(t1);
  }
  else if (d.Key == "Type2") {
    t2 = (Type2) d.Value;
        ProcessType2(t2);
  }
  else if (d.Key == "Type3") {
    t3 = (Type3) d.Value;    
        ProcessType3(t3);
  }

}
  • 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-23T12:11:47+00:00Added an answer on May 23, 2026 at 12:11 pm

    You could do:

    MyFunction (object arg) {
        if (arg is Type1) { ProcessType1(arg as Type1); }
    
        else if (arg is Type2) { ProcessType2(arg as Type2); }
    
        else if (arg is Type3) { ProcessType3(arg as Type3); }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some functions that I am calling and they take some time (milliseconds),
Let's suppose that I have a list of elements, and I want to select
I have a fairly complicated function that takes several double values that represent two
I have an array of values that is passed to my function from a
I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this
Suppose I have a C function: void myFunction(..., int nObs){ int myVec[nObs] ; ...
I have a Status class in C#, used like this: Status MyFunction() { if(...)
I'm looking for a way to have a function such as: myFunction({Key, value}, {Key2,
Inside my template function I have the following code: TypeName myFunction() { TypeName result;
If I have the following code: MyClass pClass = new MyClass(); pClass.MyEvent += MyFunction;

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.