I have this line of code
merchant = string.Format("{0} {1}", person.FirstName, person.LastName);
what is the correct way to get values out of the variable using .
notation?
Is there a way from this to do that?
I have this line of code
merchant = string.Format("{0} {1}", person.FirstName, person.LastName);
what is the correct way to get values out of the variable using .
notation?
Is there a way from this to do that?
If this is some kind of serialization and you just need to parse the result string later, then the following code can help you:
merchant = string.Format("{0} {1}", person.FirstName, person.LastName);
var result = merchant.Split(" ", StringSplitOptions.RemoveEmptyEntries);
// this ^ won't work if firstName or lastName contain spaces, so you can use another separator:
merchant = string.Format("{0}#{1}", person.FirstName, person.LastName);
var result = merchant.Split("#", StringSplitOptions.RemoveEmptyEntries);
var firstName = result[0];
var lastName = result[1];
But it is not an object, it is just a string.
Make Merchent a type first so you can access the properties of its object with "." notation.
Then you can access it in the main class like this .