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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:42:25+00:00 2026-05-11T19:42:25+00:00

I’m using an API that has a method that requires this type of argument:

  • 0

I’m using an API that has a method that requires this type of argument:

System.Collections.ObjectModel.Collection<GenericTickType> genericTickList

How do I instantiate an object for that argument? Here’s what I’ve tried but it keeps saying that the method call has some invalid arguments.

List<TickType> ticks_to_get = new List<TickType> { TickType.Price };

I’ve tried instantiating a Collection directly instead of a List and that doesn’t seem to work.

  • 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-11T19:42:25+00:00Added an answer on May 11, 2026 at 7:42 pm

    “I’ve tried instantiating a Collection directly instead of a List and that doesn’t seem to work.”

    What error do you get? You can definitely create an instance of Collection<T> directly, it is not an abstract class and it has several public constructors, including one that’s parameter-less. You can do this, for example:

    var values = new System.Collections.ObjectModel.Collection<int> { 1,2,3,4 };
    

    I noticed your sample code has a GenericTickType and a TickType. Is this a mistake or do you actually have two classes? You said it’s an enum (which one?), so one cannot possibly derive from the other. If they are two enum types, Collection<GenericTickType> and Collection<TickType> are two different classes and one is not assignable to the other.

    Now, if TickType is castable to GenericTickType (and they probably are if they are both enums, and assuming they share the same numeric values), you still cannot cast Collection<TickType> to Collection<GenericTickType>. There’s no contra/co-variance in C# for most classes yet (coming in C# 4). But you could cast each TickType by doing something like this:

    List<GenericTickType> list = new List<GenericTickType> { (GenericTickType)TickType.Price };
    list.Add((GenericTickType)TickType.Price); // add more...
    Collection<GenericTickType>genericTicks = new Collection<GenericTickType>(list);
    

    If you already have a List<TickType> and have access to C# 3.0 and LINQ, you can do this:

    List<TickType> ticks = new List<TickType> { TickType.Price };
    list.Add(TickType.Price); // add more...
    List<GenericTickType> castedList = ticks.Cast<GenericTickType>().ToList();
    Collection<GenericTickType>genericTicks = new Collection<GenericTickType>(castedList);
    

    This uses the LINQ Cast<T>() and ToList<T>() extension methods to cast each TickType in the original list to GenericTickType and creating a new List<GenericTickType> which is used to instantiate the Collecion<GenericTickType>. (I avoided using var so you could see the types in each step).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Does anyone know how can I replace this 2 symbol below from the string
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

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.