Runtime vs. Compile time

前端 未结 27 1372
后悔当初
后悔当初 2020-11-22 06:50

What is the difference between run-time and compile-time?

27条回答
  •  故里飘歌
    2020-11-22 07:26

    I think of it in terms of errors, and when they can be caught.

    Compile time:

    string my_value = Console.ReadLine();
    int i = my_value;
    

    A string value can't be assigned a variable of type int, so the compiler knows for sure at compile time that this code has a problem

    Run time:

    string my_value = Console.ReadLine();
    int i = int.Parse(my_value);
    

    Here the outcome depends on what string was returned by ReadLine(). Some values can be parsed to an int, others can't. This can only be determined at run time

提交回复
热议问题