本文介绍了什么是错误的代码和为什么它不运行当我尝试在C#中运行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 数组carPark [ 10 ] [ 2 ]; String carName; String carPlate; int i = 0 ;我< carPark的大小; i = i + 1 int b = 0 ; i < 2 ; b = b + 1 carPark [i] [b] = empty; // 来宾时 carName = Userinputs name; carPlate =用户输入牌; int i = 0 ,我< carPark的大小; i = i + 1 int b = 0 ; b将2; b = b + 1 如果 carPark [i] [b] == /等于 empty carPark [i] [b] = carName; carPlate [i] [b + 1] = carPlate; return 汽车已放置在太空 + i return 没有剩余空格 // 当客人离开时 for int i = 0 ,i< ; carPark的大小; i = i + 1 int b = 0 ; b将2; b = b + 1 如果 carPark [i] [b] == /等于carName carPark [i] [b] = empty carPark [i] [b + 1] = empty return 汽车已放置在空间 + i return 找不到汽车 解决方案 1。错误:代码包含伪代码,你应该填写必要的代码行。 2.为什么不运行:它不运行,因为它不是有效的C#代码。 BTW:它甚至不是一个完整的程序。那么为什么要运行? 干杯! 好吧,主要原因是编译器不理解它。 在此之前,您的程序甚至不作为可执行文件存在。 就好像一位日本演讲者坐下来一样在你的起居室里,开始说出随意的英语单词:你理解每一个单词,但顺序和背景没有任何意义,所以除了试图让他明白你不知道他不知道他在说什么之外什么也做不了。 停止你正在做的事情,回到你的课程开始,然后开始查看C#的语法以及每个语句的作用。 几乎每一行都有问题(而那些不存在的问题主要是评论):所以你需要回到基础,然后再开始思考如何编写正确的代码! Array carPark[10][2]; String carName; String carPlate; for int i = 0;i < size of carPark; i = i+1 for int b = 0;i < 2; b = b+1 carPark[i][b] = "empty"; // When guest comes carName = Userinputs name; carPlate = User inputs plate; for int i = 0, i< size of carPark; i = i+1 for int b = 0; b<2; b= b+1 if carPark[i][b] ==/equals to "empty" carPark[i][b] = carName; carPlate[i][b+1] = carPlate; return "Car has bee placed at space " + i return "No empty spaces left" // When guest leaves for int i = 0, i< size of carPark; i = i+1 for int b = 0; b<2; b= b+1 if carPark[i][b] ==/equals to carName carPark[i][b] = "empty" carPark[i][b+1] = "empty" return "Car has bee placed at space " + i return "Car not found" 解决方案 1. Whats wrong: The code contains pseudocode where you are supposed to fill in essential code lines.2. Why doesn't it run: It doesn't run, because it is not valid C# code.BTW: It isn't even a complete program. so why should it run?Cheers!Well, the major reason is that the compiler doesn't understand it.And until it does, your program doesn't even exist as an executable file.It's as if a Japanese speaker had sat down in your living room and started speaking random words of English: you understand each word, but the order and context make no sense, so there is nothing you can do except try to make him understand that you don;t know what he is talking about.Stop what you are doing, go back to the beginning of your course, and start looking at the syntaxt of C# and what each statement does.Almost every single line of that has a problem (and the ones that don't are mostly comments): so you need to go right the way back to the fundamentals and start thinking again about how to write correct code! 这篇关于什么是错误的代码和为什么它不运行当我尝试在C#中运行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 16:01