SHRI
SHRI

Reputation: 2466

array of strings as property in C#

Consider the code below,

private void Convert_Click(Object sender, RoutedEventArgs e)
{
          string[] strCmdLineParams = { "str1", "str2", "str3" };

          FormatterUI format = new FormatterUI();
          format.CmdLineParams = strCmdLineParams;
          format.ExecuteRequest();
}

public class FormatterUI
{
          string[] args;

          public string CmdLineParams
          {
              set
              {
                  args=value;
              }
          }

          public void ExecuteRequest()
          {
              //something
          }
}

I want to pass the strings present in strCmdLineParams to ExecuteRequest method as property. But the above code is an error. How can I do this? Please help.

Upvotes: 0

Views: 209

Answers (5)

ABH
ABH

Reputation: 3439

Or smiply ...

public class FormatterUI 
{       
    public string[] CmdLineParams
    {  
        set;   
        private get;
    } 

    public void ExecuteRequest()
    {
       //something
    }
}

Upvotes: 1

Kishore Kumar
Kishore Kumar

Reputation: 12864

public class FormatterUI 
{       
    string[] args;        
    public string[] CmdLineParams
    {           
        set           
        {               
            args=value;           
        }       
    } 
}

Declare property with a string[]

Upvotes: 1

Mike Simmons
Mike Simmons

Reputation: 1298

Property CmdLineParams should be a string[] not a string

Upvotes: 2

Andras Zoltan
Andras Zoltan

Reputation: 42333

The type of the property is wrong:

public string[] CmdLineParams 
{ 
  set 
  { 
    args=value; 
  } 
} 

Upvotes: 2

Aliostad
Aliostad

Reputation: 81660

Define property as string array:

public class FormatterUI
{
      string[] args;

      public string[] CmdLineParams // HERE!!!!
      {
          set
          {
              args=value;
          }
      }

Upvotes: 4

Related Questions