Click here to Skip to main content
15,905,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to add Listbox item saved in XML page, im new to array of String, How to Use Array of string to get listbox item one by one.

How to Resolve this ??

Thank You,

What I have tried:

C#
string[] Number;
       private SOTA_whitelist_Number RetrieveSOTAConfiguration()
       {

           int i = 1;
           for (i = 1; i < ListBox_PhoneNumber.Items.Count; i++ )
           {
               Number[i] = ListBox_PhoneNumber.Items[i].ToString();
           }
               return new SOTA_whitelist_Number(Number);
       }


C#
public SOTA_whitelist_Number(string[] Number)
        {
            this.whitelist_Number = new st_SOTA_Whitelist_Number(Number.ToCharArray());        
            
            this.Number[i] = Number[i];
        }

        //Setter and Getters
        public string NUMBER
        {
            set { Number = value; OnPropertyChanged("Number"); }
            get { return Number; }
        }
        //Methods  
        public void PrintSOTAConfiguration()
        {
            Console.WriteLine("\n NUMBER1: {0}", NUMBER1);
        }
        public st_SOTA_Whitelist_Number getStructure()
        {
            return whitelist_Number;
        }

        public void setSOTAwhitelist_Number(st_SOTA_Whitelist_Number whitelist_Num)
        {
            NUMBER1 = whitelist_Num.NUMBER1;
        }
        
        //PAYLOAD STRUCTURE
    [StructLayout(LayoutKind.Sequential, Pack = 0)]
    public struct st_SOTA_Whitelist_Number
    {
        char[] Number;
        ushort payload_length;
        
        //Constructor
        public st_SOTA_Whitelist_Number(char[] Number1)
        {
            this.Number = new char[CommandDefine.MAX_SIZE.MAX_NUMBER1_STR_SZ];
            
            Common.InitToZero(ref this.Number);

            Array.Copy(Number,  this.Number,  Number.Length);

            Console.WriteLine("Constructor..");
            this.payload_length = CommandDefine.MAX_SIZE.MAX_NUMBER1_STR_SZ;
        }


its Shows Error as :
1. 'System.Array' does not contain a definition for 'ToCharArray' and no extension method 'ToCharArray' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)	
2. Cannot implicitly convert type 'string[]' to 'string'	
Posted
Updated 15-Jan-20 21:29pm
v2

Look at your code:
C#
public SOTA_whitelist_Number(string[] Number)
        {
            this.whitelist_Number = new st_SOTA_Whitelist_Number(Number.ToCharArray());
Number is an array of strings, that is defined by teh method declaration.
An array of strings is a collection of collections of characters (because each string is a collection of characters, and and array is a collection).
You can't convert a collection of collections of characters to a array of characters!

What I suspect you want to do is pass a single string from the collection into the SOTA_whitelist_Number instead of the whole array, which means changing the method definition, and the call to it - but which one I have no idea!
 
Share this answer
 
In all it seems that you didn't made up your mind where you need a string and where you need an array of them...
Looking at the loop you have in the first code block, the method SOTA_whitelist_Number should receive a parameter of string and not string[]...
 
Share this answer
 
Quote:
this.whitelist_Number = new st_SOTA_Whitelist_Number(Number.ToCharArray());
You are trying to retrieve an array of characters from an array of strings. That's probably a logic error (as well as syntax error).

Quote:
this.Number[i] = Number[i];
What is i in such a context? It looks another logical error.
 
Share this answer
 
Comments
Member 14672509 16-Jan-20 3:57am    
then how to convert array of character to array of strings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900