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

The Archive Base Latest Questions

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

public static class Tracking { public static List<TrackList<T>> Lists = new List<TrackList<T>>(); public static

  • 0
    public static class Tracking
    {

        public static List<TrackList<T>> Lists = new List<TrackList<T>>();

        public static List<TrackedDictionary<K,V>> Dictionaries =new List<TrackedDictionary<K,V>>()

        public static void Register<K,V>(TrackedDictionary<K,V> dictionary)
        {
            Dictionaries.Add(dictionary);
        }

        public static void Register<T> (TrackList<T> list)
        {
            Lists.Add(list);
        }
    }

public class TrackList<T> : List<T>
    {
        private string ListName = null;
        private int AvgSize;

        public TrackList ()
        { }

        public TrackList (string listname, int avgsize)
        {
            this.ListName = listname;
            this.AvgSize = avgsize;
            Tracking.Register(this);
        }

        public int GetListSize ()
        {
            return this.Count * this.AvgSize;
        }
    }

public class TrackedDictionary<K, V> : Dictionary<K, V>
    {
        public string DictionaryName = null;
        public byte AvgSize;

        public TrackedDictionary ()
        { }

        public TrackedDictionary (string dictionaryname, byte avgsize)
        {
            this.DictionaryName = dictionaryname;
            this.AvgSize = avgsize;
            Tracking.Register(this);
        }

        public int GetDictionarySize ()
        {
            return this.Count * this.AvgSize;
        }
    }
  • 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:31:47+00:00Added an answer on May 25, 2026 at 6:31 am

    You haven’t declared Tracking as a generic type, so T, K and V have no meaning. You can do so easily enough:

    public static class Tracking<T, K, V>
    {
        ...
    }
    

    Note that you’ll now have separate Lists, Dictionaries etc fields per concrete type. You’ll need to make the methods non-generic though.

    An alternative is to have a top-level non-generic class, with generic methods and generic nested types:

    public static class Tracking
    {
        private static class ListHelper<T>
        {
            internal static List<TrackList<T>> Lists = new List<TrackList<T>>();
        }
    
        private static class DictionaryHelper<K, V>
        {
            internal static List<TrackedDictionary<K,V>> Dictionaries =
                new List<TrackedDictionary<K,V>>()
        }
    
        public static void Register<K,V>(TrackedDictionary<K,V> dictionary)
        {
            DictionaryHelper<K, V>.Dictionaries.Add(dictionary);
        }
    
        public static void Register<T> (TrackList<T> list)
        {
            ListHelper<T>.Lists.Add(list);
        }
    }
    

    I’d also strongly advise against public fields like this… and against using statics widely to start with, given the problems they cause for testability.

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

Sidebar

Related Questions

public static class MyClass { public static void Add<T>(this List<T> list, T item) {
I have this class: public static class CsvWriter { private static StreamWriter _writer =
Let's say I have a class called AppConfig: public static class AppConfig { private
I've got this public static class MyClassHelper { DataContex db = new DataContext(); public
Consider this code snippet: public static class ApplicationContext { private static Func<TService> Uninitialized<TService>() {
Consider: static class EntranceClass { public: static void RegisterSomething() { } static int main()
public class TowThreads { public static class FirstThread extends Thread { public void run()
My code is public static class ContainerBootstrapper { public static void BootstrapStructureMap() { ObjectFactory.Initialize(x
I have the following code: public class DeserializeAndCompare { public static List<string> IntoXML() {
This is a contrived example: public static class MyExtensions { public static void MyMethod(

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.