‫Welcome back.
‫In this video, we're going to check out the tripods method, which allows us to convert strings into
‫numeric data types.
‫And there are multiple situations where you actually need that.
‫And we're going to look at one of those.
‫So for example, we can use the tri pass method to convert a string like 128 into a numeric data type
‫like an integer.
‫And here it's important that we have the quotation marks surrounding the 128 because this is not a number,
‫it's actually a string.
‫So it's text.
‫And as you know, the data type does matter in C-sharp.
‫All right.
‫Powers often gets used when the user submits input.
‫So for example, the user enters his name, but the data entered is a string.
‫So we need to convert that into a number in order to work with it.
‫And here's an example.
‫We have the main method in which we have the string called number as string, which has a value of 128.
‫So we need that string, of course, in order to convert that into an integer or so, in order to parse
‫it into an integer.
‫So create a variable to store the parsed value.
‫In this case, I'm just calling it int parsed value and then we try to parse the string and that returns
‫a boolean.
‫So we have our main method with our parsed value and we create this bool called success where we use
‫int dot, try parse.
‫So this try parse method is available within our INT data type.
‫We're going to look into many more methods later on which are built in in C sharp and there are thousands
‫of them and you can use them in order to make your code a lot more useful, practical and advanced.
‫And what we're doing with these tripwires is we are taking an integer in which is our number as string,
‫and we are storing the value that is the result of our try to parse it in the past value variable.
‫So the bool itself will be either true or false saying okay, it worked so I could parse or convert
‫the 128 string into an integer, and if it's false, then it just means that it didn't work.
‫So for example, there was a wrong character in there.
‫Let's say there was an X in there as well, or the value given was not a string or something like that.
‫So that's what we need is these are the steps.
‫And then of course we can use parsed value as an integer and that will pretty much just be the result
‫of our whole work that we did here.
‫So it will be the result of our parse approach.
‫We can then use this result to write something, for example, on our console.
‫This is a very basic example so that you can already test it yourself.
‫So if success is true, so our boolean, which was the result of our tripartite method, so either it
‫worked to parse it or it didn't work.
‫So here it's just going to say something like parsing successful number is and then it will just show
‫us the parsed value or it wasn't successful and it will just say parsing failed.
‫So this is then basically the structure that we're using here where we have if an LS, so if a specific
‫condition is met, do something.
‫If it's not met, do ls, so do something else.
‫And in this case, the ls block All right, so you can also use other numeric data types for parsing
‫like float or double, so you're not limited to integers.
‫Float, try, parse.
‫So you can see here in float we also have this tri parse method.
‫It's all the same, except that instead of integer we're now using float.
‫So we have float as the dating data type and we also use the float try parse method.
‫So here it's important that we of course adjust it to the data type that we want to look at.
‫So if it was successful, then it will say parsing was successful and otherwise it will just say parsing
‫failed.
‫So here, of course, this is a 128, which is a integer.
‫So we could of course use integer instead.
‫But let's have a look at examples where parsing will fail and where string cannot be converted into
‫a desired data type.
‫So for example, integer or float or double.
‫All right, so parsing to an end, we can see what works.
‫So String H 18, it's possible to convert or parse that into an integer.
‫However.
‫H equals 18 x, y, z will not be possible here.
‫So we cannot parse that into an integer.
‫And for the float here, same story.
‫We have 18.75 as an example and then that will of course work.
‫But at the same time 18.75 x, y, z will not work and it doesn't have to be x, y, z just could be
‫X or a or D or whatever character that just doesn't fit the structure of a float.
‫All right.
‫So I'd say let's go into practical example where we see that life in action.
‫And yeah, thank you for watching.