Hi Guys,

Is it possible to add a string to a list using a static method or am i really misunderstanding this?

This is what i'm trying...

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LDAPNOCISCO
{
    class STOREUDPs
    {
        private static List<string> UDPList = new List<string>();

        public static List<string> UDPListStore
        {
            get { return UDPList; }
            set { UDPList.Add(value.ToString()); }
        }
    }
}

then i'm trying to add to UDPList using

builder.Append(DN.ToString() + "," + ModelButton[0] + "," + PhoneButtonTemplate + "," + "All Features"
                    + "," + "," + "," + "," + "," + TheRest.ToString() + "," + noOfLines);
                STOREUDPs.UDPListStore = builder.ToString();

im getting a "cannot convert string to list<string> error though...

any advice?

Recommended Answers

All 4 Replies

You need to call the .Add method instead of trying to set the List to the string. You have the .Add method in your property setter, but that's not going to be called with your given syntax.

i got it working doing this sort of thing...

is this what you meant?

STOREUDPs.UDPListStore(builder.ToString());
class STOREUDPs
    {
        private static List<string> UDPList = new List<string>();
        private static string Site;
        private static int Mostlines;
        private static ListBox LBProgress;

        public static void  UDPListStore(string NewUDP)
        {
            UDPList.Add(NewUDP);
        }
        public static List<string> UDPReturner
        {
            get { return UDPList; }
        }
}

Yes, that will work.

Although if I could offer a suggestion on your method name, put the verb as the first word. StoreInUDPList or AddToUDPList. The meaning is clearer and conforms to C# standards for method names.

Cool, Thanks for the info! that makes sense

Dan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.