如何解决这个C#问题? [英] How to solve this C# problem?

查看:93
本文介绍了如何解决这个C#问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我今天刚刚开始编码,并且遇到了我的代码中的一些错误,我无法清除。我已经修复了代码中的一些错误,但仍然无法修复所有错误。



我有两个请求:



1.请指出错误的位置。

2.将来如何为自己修复错误?



这是代码:



 命名空间 ConsoleApp1 
{
class 程序
{
静态 void Main( string [] args)
{
// 创建变量
string StudentInformation = ;
string firstName = ;
string lastName = ;
DateTime birthDate;
string 地址行 1 = ;
string 地址行 2 = ;
string city = ;
string 州/省= < /跨度>;
int Zip / Postal = 0 ;
string Country = ;


// 指定一些值

StudentInformation = 学生信息;
firstName = Hans;
lastName = Brönimann;
birthDate = new DateTime( 1990 4 1 );
地址行 1 = Musterstrasse 1 ;
地址行 2 = Hinterzimmernquartier< /跨度>;
city = Entenhausen;
州/省= 拜仁;
Zip / Postal = 11211;
Country = Belmuga;

// 使用只有变量名称的简单输出
控制台.WriteLine(名字);
Console.WriteLine(lastName);
}
}
}





我尝试了什么:



我检查了Visual Studio的提示,并尝试使用类似的代码自行修复它,没有错误。

解决方案

嗯,明显的错误是变量名不能包含空格或其他特殊字符,如/:

标识符名称| Microsoft Docs [ ^ ]



以下是无效的变量名称:

  • 地址第1行
  • 地址第2行
  • 州/省
  • 邮编/邮政


我强烈建议您遵循一些关于该语言的正确教程。如果你今天刚刚开始,那么你最初会发现它很难,你不能通过在这里发帖来学习。下载 Charles Book Zero,Charles Petzold [ ^ ] 并按照自己的方式进行操作。你会发现时间花得很好。



正确的链接是:

http://www.charlespetzold.com/dotnet/index.html [ ^ ]


第一个解决方案的附加:无需在多个步骤中创建,初始化和分配变量。

您可以像这样一步完成:



  / *   
//创建变量
string StudentInformation =;

//分配一些值
StudentInformation =学生信息;
* /


// 创建和分配变量
string StudentInformation = 学生资料;


Hello everybody,

I just started out coding today and got stuck with some bugs in my code which I cannot clear. I already fixed a couple of mistakes in the code but still I cannot fix all of them.

I have two requests:

1. Please point out where the mistakes are.
2. How can I fix mistakes in general for myself in the future?

This is the code:

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
                // create variables
                string StudentInformation = "";
                string firstName = "";
                string lastName = "";
                DateTime birthDate;
                string Address Line 1 = "";
                string Address Line 2 = "";
                string city = "";
                string State/ Province = "";
                int Zip/ Postal = 0;
                string Country = "";


                // Assign some values

                StudentInformation = "Student Information";
                firstName = "Hans";
                lastName = "Brönimann";
                birthDate = new DateTime(1990, 4, 1);
                Address Line 1 = "Musterstrasse 1";
                Address Line 2 = "Hinterzimmernquartier";
                city = "Entenhausen";
                State / Province = "Bayern";
                Zip / Postal = "11211";
                Country = "Belmuga";

                // use simple output with just variable name
                Console.WriteLine(firstName);
                Console.WriteLine(lastName);
            }
        }
    }



What I have tried:

I checked the hints of Visual Studio and tried to fix it myself with a similar code without mistakes.

解决方案

Well, the obvious mistake is that variable names cannot contain spaces or other special characters like "/":
Identifier names | Microsoft Docs[^]

The following are not valid variable names:
  • Address Line 1
  • Address Line 2
  • State / Province
  • Zip / Postal


I strongly suggest you follow some proper tutorials on the language. If you only started today then you are going to find it hard going at first, and you cannot learn by posting here. Download a copy of .NET Book Zero, by Charles Petzold[^] and work your way through it. You will find it time well spent.

Correct link is:
http://www.charlespetzold.com/dotnet/index.html[^]


Additional to the first Solution: No need to create, initialize and assign variables in many steps.
You can do it in one step like this:

/*
// create variables
string StudentInformation = "";

// Assign some values
StudentInformation = "Student Information";
*/

// create and assign variables
string StudentInformation = "Student Information";


这篇关于如何解决这个C#问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆