Difference between type casting and parsing?

What is the big difference between parsing and typing? I am trying to use type casting to a string and this gives me an error.

Something like that:

string str = "10";
int i = (int) str;
+3
source share
2 answers

In order to work with a type, types must be compatible:

object str = 10;
int i = (int) str;

An analysis is a conversion between different types:

string str = "10";
int i = int.Parse(str);
+4
source

Casting works when objects have part of the inheritance. But in your case

int i = (int) str;

. /losen .NET.

Int32.Parse(...

, , .

0

Source: https://habr.com/ru/post/1766774/


All Articles