Does this course discuss the Parse and Tryparse method. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does this course discuss the Parse and Tryparse method.

As I'm only still getting past methods, I've just been seeing Parse or Tryparse in numerous practice codes out there, and although the Web has given me a very slight understanding of it. What exactly do these do? Or when does the course get into such. It seems important for future codes in C#.

6th Oct 2016, 12:43 PM
Logan Gardner
Logan Gardner - avatar
1 Answer
+ 4
Parse and TryParse methods are meant to "convert" some string representation to the object's internal representation. You can parse for example numbers, but also IP addresses or anything that can be serialized to string and the designer of the handling class implemented any of these. Typically they are static members of classes and structures that take a string and return an instance of that object. The difference between the two is that Parse will throw an exception if the string can not be parsed - like it is an incorrect string representation. TryParse usually has an out parameter, and it return a bool. It will put the result of the conversion in the out parameter, and return true if succeeded. And of course does not throw any exception.
6th Oct 2016, 2:46 PM
Zoltán Zörgő
Zoltán Zörgő - avatar