ArteS ArteS - 1 year ago 57
C# Question

How to change the input array using a TextBox?

How to change the array to enter the desired format in TextBox'e?
Here is the code:

private static readonly string[] Extensions = new string[] { textbox1.text };

In the fields of { } must be changed to textbox!

In the text box I want so I can introduce such formats using a comma! txt,png,ico,dll

Or better using List?

List<string> mylist = new List<string>() { "*.txt" };

enter image description here

Wish I could enter my desired formats is not in the code {"*.txt"}! And TextBox'e .


private static string[] Extensions = new string[] { "*.txt" };
//public static string[] Extensions;
public static void extractExtensions(string s)
Extensions = s.Split(',');

And how do I assign values to string [] { "of the textbox"};

Answer Source

It is not easy to understand what you are really having problems with, but try this:

textbox1.Text = String.Join(",", Extensions);

the reverse would be from textbox --> array:

string [] singleExtensions = textbox1.Text.Split(',');

this would give you all the elements which were separated by a , and dump them into the array.

Or if you prefer Lists:

List<string> singleExtensions = textbox1.Text.Split(',').ToList();


Ok since you don't want to post more code, I make a wild guess:

I imagine you have a Windows Forms application and a TextBox in a Form1. You also should have an instance of the class that you want to use in there. Let's assume the class is called MyClass and it has an array for the extensions, and a method extractExtensions to extract the extensions:

public class MyClass
    string [] singleExtensions;

    public void extractExtensions(string s)
        singleExtensions = s.Split(',');


public partial class Form1 : Form
    // instance of class:
    MyClass _myClass = new MyClass();

at a certain point in your Form you want to call the method of your class and pass the content of the textbox like this:


and voilĂ .