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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:49:47+00:00 2026-05-18T19:49:47+00:00

private List<T> newList; public List<T> NewList { get{return newList;} set{newList = value;} } I

  • 0
private List<T> newList;

public List<T> NewList
{
get{return newList;}
set{newList = value;}
}

I want to create something like this, but this is won’t work. it’s just an example to demonstrate my goal as it’s pretty common creating proprties for string and int and even T but I’ve never seen a List property
Is it even possible do such a thing, creating a property for type List ?

EDIT

I have a normal class that has normal properties (string properties, int properties, etc) but I have this property that stores user options, So on the presentation layer I had to convert them into a string so I could be able to store them in the Object. Now is it possible to have a property of type List to store the multivalues in a better and clean way, instead of converting information into one string and then split it and again join it! Thanks Again =D

EDIT2

private List<KeyValuePair<string, string>> _settings;

public List<KeyValuePair<string, string>> MySettings
{
    get { return _settings; }
    set { _settings = value; }
}

I used the exact code you posted but the property still won’t appear in the object’s instance, so I tried adding code in the get and set (I wonder why you left them empty or does it means something?) and also added a private variable in the class but still it doesn’t appear in the properties of the object’s instance!

I hope you could provide the exact code to implement this property and a simple code that assigns or retrieves from/to an instance of this class object
It’s the first time to even hear about this KeyValuePair and all the tutorials are pretty simple and not for my case, sorry!

The Last Edit: After a lot of researching and the help of Mark Avenius I found the perfect answer. hope everyone can benefit from this.

NOW! HOW TO CREATE A PROPERTY FOR A LIST :

The Options Class

Public Class Options
{
        private string id;
        private int option;

        public int ID
        {
            get { return id; }
            set { id= value; }
        }

        public string Option
        {
            get { return option; }
            set { option = value; }
        }
}

The Users Class

public class Users

{
        private int userId;
        private string pass;
        private List<Options> userOptions = new List<Options>();


        public int ID
        {
            get { return userId; }
            set { user = userId; }
        }

        public string Pass
        {
            get { return pass; }
            set { pass = value; }
        }

        public List<Options> OptionsList
        {
            get { return userOptions; }
            set { userOptions = value; }
        }
}

The Presentation Layer

    Users newUser = new Users ();
    Options userOption = new Options ();

    userOption.ID = int.Parse(txtBxID.Text);
    userOption.Option = txtBxOption.Text;

    Item.Options.Add(userOption);
  • 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-18T19:49:48+00:00Added an answer on May 18, 2026 at 7:49 pm

    T must be defined within the scope in which you are working. Therefore, what you have posted will work if your class is generic on T:

    public class MyClass<T>
    {
        private List<T> newList;
    
        public List<T> NewList
        {
            get{return newList;}
            set{newList = value;}
        }
    }
    

    Otherwise, you have to use a defined type.

    EDIT: Per @lKashef’s request, following is how to have a List property:

    private List<int> newList;
    
    public List<int> NewList
    {
        get{return newList;}
        set{newList = value;}
    }
    

    This can go within a non-generic class.

    Edit 2:
    In response to your second question (in your edit), I would not recommend using a list for this type of data handling (if I am understanding you correctly). I would put the user settings in their own class (or struct, if you wish) and have a property of this type on your original class:

    public class UserSettings
    {
     string FirstName { get; set; }
     string LastName { get; set; }
     // etc.
    }
    
    public class MyClass
    {
     string MyClassProperty1 { get; set; }
     // etc.
    
     UserSettings MySettings { get; set; }
    }
    

    This way, you have named properties that you can reference instead of an arbitrary index in a list. For example, you can reference MySettings.FirstName as opposed to MySettingsList[0].

    Let me know if you have any further questions.

    EDIT 3:
    For the question in the comments, your property would be like this:

    public class MyClass
    {
        public List<KeyValuePair<string, string>> MySettings { get; set; } 
    }
    

    EDIT 4: Based on the question’s edit 2, following is how I would use this:

    public class MyClass
    {
        // note that this type of property declaration is called an "Automatic Property" and
        // it means the same thing as you had written (the private backing variable is used behind the scenes, but you don't see it)
        public List<KeyValuePair<string, string> MySettings { get; set; } 
    }
    
    public class MyConsumingClass
    {
        public void MyMethod
        {
            MyClass myClass = new MyClass();
            myClass.MySettings = new List<KeyValuePair<string, string>>();
            myClass.MySettings.Add(new KeyValuePair<string, string>("SomeKeyValue", "SomeValue"));
    
            // etc.
        }
    }
    

    You mentioned that “the property still won’t appear in the object’s instance,” and I am not sure what you mean. Does this property not appear in IntelliSense? Are you sure that you have created an instance of MyClass (like myClass.MySettings above), or are you trying to access it like a static property (like MyClass.MySettings)?

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

Sidebar

Related Questions

private string? typeOfContract { get { return (string?)ViewState[typeOfContract]; } set { ViewState[typeOfContract] = value;
Assume the following class: public class MyEnum: IEnumerator { private List<SomeObject> _myList = new
Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private
. private void Form1_Load(object sender, EventArgs e) { List<CaclulatedData> tests = new List<CaclulatedData> {
abstract class Foo { private List<Object> container; private bool update; Foo Foo() { container
Is it better to initialize class member variables on declaration private List<Thing> _things =
I have the following method in my code: private bool GenerateZipFile(List<FileInfo> filesToArchive, DateTime archiveDate)
How do I list and export a private key from a keystore?
Consider the following code: private static void WriteProcesses(StreamWriter sw, DateTime d) { sw.WriteLine(List of
Hopefully a simple question. Take for instance a Circularly-linked list: class ListContainer { private

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.