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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:04:58+00:00 2026-05-25T06:04:58+00:00

Im looking for a way to replace the following: public class NonTypeSafe { private

  • 0

Im looking for a way to replace the following:

public class NonTypeSafe
{
    private List<object> contents = new List<object>();
    public List<object> Contents {get { return contents; }};

    public NonTypeSafe(params object[] arguments)
    {
        foreach(object arg in arguments)
        {
            contents.Add(arg);
        }
    }
}

with something that is typesafe. The aim is to have an object into which i can add numerous objects of varying types. At present, checks have to be made when retrieving the objects to determine whether or not they are of the correct type / in the correct order.

At present i have the following:

public class TypeSafe<T1>
  {
    protected List<object> ArgList = new List<object>();

    private readonly T1 arg1;

    public TypeSafe(T1 arg1)
    {
      ArgList.Add(arg1);
      this.arg1 = arg1;
    }

    public T1 Arg1
    {
      get { return (T1) ArgList[ArgList.IndexOf(arg1)]; }
    }
  }



  public class TypeSafe<T1, T2> : TypeSafe<T1>
  {

    private readonly T2 arg2;

    public TypeSafe(T1 arg1, T2 arg2) : base(arg1)
    {
      ArgList.Add(arg2);
      this.arg2 = arg2;
    }

    public T2 Arg2
    {
      get { return (T2) ArgList[ArgList.IndexOf(arg2)]; }
    }
  }

And so on, adding new classes up to largest number parameters i would reasonably expect. Is there a better way to achieve this?

  • 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-25T06:04:59+00:00Added an answer on May 25, 2026 at 6:04 am

    Are you re-inventing System.Tuple?

    A tuple is a data structure that has a specific number and sequence of elements. An example of a tuple is a data structure with three elements (known as a 3-tuple or triple) that is used to store an identifier such as a person’s name in the first element, a year in the second element, and the person’s income for that year in the third element.

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

Sidebar

Related Questions

I am looking for a way to replace the SRC attribute in all IMG
I'm looking for a way to find/replace links to images (within user-generated content) without
I'm looking for a way to do a substring replace on a string in
I'm looking for a way to make the search/replace function of VS IDE regex-aware,
I'm looking for a way to replace a string in a file without reading
I am using SSMS 2008 and am looking for a way to replace records
I'm looking for a way to write the following in only one preg_replace $url
I am looking for advice on a way to accomplish this. Given the following:
I'm looking for the best reliable way to return the first and last name
Is there a far shorter way to write the following code? my_string = my_string.replace('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.