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

  • Home
  • SEARCH
  • 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 8474533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:39:08+00:00 2026-06-10T17:39:08+00:00

I have a function in C# void func(int x, int y, params object[] arr)

  • 0

I have a function in C#
void func(int x, int y, params object[] arr)

Now this arr can contain anything. For e.g. it can contain an array at [0], a string at [1] and so on.

If I pass the following parameters: func(3, 4, array1, list1, "hello");

array1 is an Array of int, list1 is a List

My question is that how do I extract array1 and list1 from arr and convert it to an Array or List?

  • 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-10T17:39:09+00:00Added an answer on June 10, 2026 at 5:39 pm

    Here is a small program. You have mentioned that the arr can be made of anything, so I presume that on the first index there can be List, array, string or anything else, and that there can be many arrays or lists passed.

    Therefore you should probably not presume that on particular indexes you can expect elements of particular type.
    This solution will extract you all arrays and all lists from arr. Maybe it could be useful for you.

    class Program
    {
        static void Main(string[] args)
        {
            int[] array1 = new int[10];
            var list1 = new List<int>() { 0, 1, 52 };
            var list2 = new List<string>() { "Mike" };
    
            func(3, 4, array1, list1, "hello", list2);
    
        }
    
        static void func(int x, int y, params object[] arr)
        {
            // Gets all lists and arrays from arr
            IEnumerable<object> listsAndArrays = arr.Where(a => a is IList);
            // Gets all arrays from arr
            IEnumerable<object> arrays = arr.Where(a => a is Array);
            // Gets all lists from arr
            IEnumerable<object> lists = arr.Where(a => a.GetType().IsGenericType && a.GetType().GetGenericTypeDefinition() == typeof(List<>));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function: void func(int a, int b, char s, FILE *fp, int
I have a function void func(int x, char *str, ...) { ... } I
I found this function definition void *func(void *param) { } Actually, I have a
I have trouble writing a recursive function in C: void func(int n) which for
Suppose I have a function that allocates memory for the caller: int func(void **mem1,
Suppose we have an array say: int arr[1000]; and I have a function that
I have a C++ function: void Func(void* param) { int a; a= (int*)param; }
I have a C++ API prototype void Func(int& size); How can I translate it
Suppose I have this function: void my_test() { A a1 = A_factory_func(); A a2(A_factory_func());
I have this function: void ToUpper(char * S) { while (*S!=0) { *S=(*S >=

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.