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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:27:42+00:00 2026-06-13T21:27:42+00:00

Generics rookie struggling to access a list inside a class which is contained in

  • 0

Generics rookie struggling to access a list inside a class which is contained in a list. Basically I am trying to list the occupations of people that the user entered (I am sure there is an easier way of doing this, but this code was made to practise generics).

Class Code

namespace GenericPersonClass
{
class GenericPerson<T>
{
    static public List<T> Occupations = new List<T>();
    string name, famName;
    int age;

    public GenericPerson(string nameS,string famNameS,int ageI, T Note)
    {
        name = nameS;
        famName = famNameS;
        age = ageI;
        Occupations.Add(Note);
    }

    public override string  ToString()
        {

            return "The name is " + name + " " + famName + " and they are " + age;
        }
  }
}

Main Code

namespace GenericPersonClass
{
class Program
{
    static void Main(string[] args)
    {
        string token=null;
        string nameS, lastNameS,occS;
        int age;
        List<GenericPerson<string>> Workers = new List<GenericPerson<string>>();

        while (token != "no" || token != "No")
        {
            Console.WriteLine("Please enter the first name of the person to input");
            nameS = Console.ReadLine();
            Console.WriteLine("Please enter the last name of the person " + nameS);
            lastNameS = Console.ReadLine();
            Console.WriteLine("How old is " + nameS + " " + lastNameS);
            age = int.Parse(Console.ReadLine());
            Console.WriteLine("What is the occupation of " + nameS + " " + lastNameS);
            occS = Console.ReadLine();
            Console.WriteLine("Enter more data?...Yes/No");
            Workers.Add(new GenericPerson<string>(nameS, lastNameS, age, occS));
            token = Console.ReadLine();
        }

        Console.WriteLine("You provide the following employment...\n");
        for (int i = 0; i < Workers.Count; ++i)
        {
            Console.WriteLine("{0} \n", Workers[0].Occupations[i]); 
//This line above is shown as wrong by VS2010, and intellisense does not see Occupations...
        }

    }
}
}

Thanks for any help,
Leo

  • 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-13T21:27:43+00:00Added an answer on June 13, 2026 at 9:27 pm

    So, you’re trying to access a static List from an instance variable. That’s the problem there. You can access this directly by using the class not the instance.

    Something like:

    GenericPerson<string>.Occupations[i]
    

    It doesn’t have anything to do with the List – it’s all about the static part.

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

Sidebar

Related Questions

I have a generics class, that uses TBase as the type parameter. Using MEF,
What generics collection class can I use that provides both mapping and array-like functionality.
This following is from generics tutorials: Say class R extends S, public void addR(List<?
We have Generics Property public class BE { private List<Admin_Fee> _Admin_Fee = new List<Admin_Fee>();
I have a generics class that I used to write data to IsolatedStorage. I
Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private
I'm learning about generics, so I'm trying to make my own generic array class,
With generics on languages like C# or Java, you can have a factory that
Consider this declaration with generics: public class BaseNode<TNode> where TNode : BaseNode<TNode> { public
I know Java's generics are somewhat inferior to .Net's. I have a generic class

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.