相关文章推荐
一身肌肉的大葱  ·  Solving the ...·  4 天前    · 
一身肌肉的大葱  ·  [SOLVED] Can't get ...·  7 月前    · 
一身肌肉的大葱  ·  kong.response - ...·  10 月前    · 
一身肌肉的大葱  ·  java lambda filter ...·  10 月前    · 
一身肌肉的大葱  ·  Google Developers ML ...·  12 月前    · 
一身肌肉的大葱  ·  Help And Training ...·  12 月前    · 
不爱学习的火腿肠  ·  java ...·  8 分钟前    · 
旅行中的铁链  ·  错误信息:SSL ShakeHand ...·  30 分钟前    · 
憨厚的金鱼  ·  Scanpy数据结构:AnnData - 何帅 ·  30 分钟前    · 
Unreachable Code Detected Understand and fix the unreachable code detected compiler warning.
C#
This page was last reviewed on May 8, 2022.
Unreachable code is never executed. The C# compiler issues an unreachable code detected warning. This warning can help you eliminate unused code.
Code notes. We look at unreachable code. We see how to eliminate this error but not remove the code—pragma directives can be used for this purpose.
This C# program has some unreachable code. In the while-loop, the condition must be evaluated before the loop body is entered. In a while false loop, all the enclosed code is unreachable.
While
And The compiler can figure this out before the program ever executes. It will generate an unreachable code detected warning.
using System; class Program static void Main() while (false) int value = 1; if (value == 2) throw new Exception(); }
Warning CS0162: Unreachable code detected
Example 2. Sometimes, you may not want to delete the unreachable code for some reason. If you comment it out, it will no longer be compiled. This can result in a phenomenon called "bit rot."
Tip With pragma warning disable, you can keep the code compiling but eliminate the error as well.
Pragma Directive
using System; class Program static void Main() #pragma warning disable while (false) int value = 1; if (value == 2)
 
推荐文章