Runtime vs. Compile time

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

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

27条回答
  •  情歌与酒
    2020-11-22 07:26

    (edit: the following applies to C# and similar, strongly-typed programming languages. I'm not sure if this helps you).

    For example, the following error will be detected by the compiler (at compile time) before you run a program and will result in a compilation error:

    int i = "string"; --> error at compile-time
    

    On the other hand, an error like the following can not be detected by the compiler. You will receive an error/exception at run-time (when the program is run).

    Hashtable ht = new Hashtable();
    ht.Add("key", "string");
    // the compiler does not know what is stored in the hashtable
    // under the key "key"
    int i = (int)ht["key"];  // --> exception at run-time
    

提交回复
热议问题