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

The Archive Base Latest Questions

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

I have a model like below public sealed class Person { public string MobileNo

  • 0

I have a model like below

public sealed class Person
{
        public string MobileNo { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
}

In my implmentation class, I have a method which takes an IEnumerable as a parameter

public string PersonList(string listName, IEnumerable<Person> persons)
{
   dictionary.Add("name", new String[1] { listname }); 
   dictionary.Add("list", persons.ToArray());

    PrivateMethod("personList", dictionary);
}

I have another private method

private string PrivateMethod(string value, Dictionary<string, object[]> parameters)
{
    foreach (KeyValuePair<string, object[]> kvp in parameters)
    {
           Person[] persons = kvp.Value.Cast<Person>().ToArray();

           [...]
    }

[...]
}

I want to make this above method reusable, and don’t want to put “Person” model tightly-coupled.

Can I use dynamic ?

ContactList(string listName, IEnumerable<dynamic> persons)

And within the private method

dynamic[] persons = kvp.Value.Cast<How to pass model here>().ToArray();

Solution:

This will work, great.

 dynamic[] persons = kvp.Value.Cast<dynamic>().ToArray();

Thanks to usr & Rune FS

  • 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-18T02:10:40+00:00Added an answer on June 18, 2026 at 2:10 am

    Have you tried using “Interfaces” in c#? you can cast any object to any type as long as they are all derived to the same type of interface.

    interface IPerson
    {
        string MobileNo { get; set; }
        string Name { get; set; }
        string LastName { get; set; }
    }
    
    class Person : IPerson
    {
        public string MobileNo { get; set; }
        public string Name { get; set; }
        public string LastName { get; set; }
    }
    
    class execute
    {
        private Dictionary<string, object[]> dictionary = new Dictionary<string,object[]>();
    
        public void run()
        {
            List<IPerson> persons = new List<IPerson>();
            persons.Add(new Person()
            {
                LastName = "asdf",
                Name = "asdf",
                MobileNo = "123123"
            });
    
            persons.Add(new Person()
            {
                LastName = "aaaa",
                Name = "dddd",
                MobileNo = "1231232"
            });
    
            string x = PersonList("somelistname", persons);
        }
    
    
        public string PersonList(string listName, IEnumerable<IPerson> persons)
        {
            //dictionary.Add("name", new String[1] { listName });
            dictionary.Add("list", persons.ToArray());
    
            return PrivateMethod("personList", dictionary);
        }
    
        private string PrivateMethod(string value, Dictionary<string, object[]> parameters)
        {
            foreach (KeyValuePair<string, object[]> kvp in parameters)
            {
                IPerson[] persons = kvp.Value.Cast<IPerson>().ToArray();
    
            }
    
            return "somestring";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a model: public class Menu { public string Name { get;
I have a model called 'UserRoleHolder' like below. @Entity public class UserRoleHolder extends Model
I have a model like below: public class CreateStockcheckJobModel { [Engineer(true)] public EngineerModel Engineer
I have written two functions like below in my model class. public function fetchByUsername($username)
I have a field in my model class like below: [ScaffoldColumn(false)] public DateTime DatePosted
i have a model say modela with a calculate field. like below class modelA
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a model like the following one: public class TestModel{ public IList<Field> Fields
I have an Area like below. Controller Class public class AdminController : Controller {
I have the code in my Helper.cs like below: public static string NoImagePath {

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.