The Split method returns a string[]
This means that if you make a ToString()
to the result of a Split
, what you will get is the name of the class ( System,String[]
).
If you want to return the first element, you must indicate the index of the string to be returned:
txtnom1.Text = lista[0].nombre_completo.Split(' ')[0].ToString();
Keep in mind that you should check that list [0] .completnamedoesn'tgive something or will throw you an exception
and if it were kevin arturo ... and I want to return the two names?
That's a different problem and a little more complex, since ... how do you know if the name is simple or compound? There is no easy solution. You could check the size of string[]
returned by Split
and if it is 4, return the first two elements as the name. But ... and if it turns out that what is composed is the last name ?. I am afraid that there is no solution for this that covers all the cases, beyond managing it in the data entry (when requesting the data, storing the name in one field and the surnames in another).