Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
See more:
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:

C#
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.
Posted
Updated 7-Dec-18 3:09am
v2

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
 
Share this answer
 
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[^]
 
Share this answer
 
v2
Comments
Leo Chapiro 7-Dec-18 10:11am    
The link to book you provided is unfortunatelly dead: HTTP Error 503. The service is unavailable. Have you checked it?
Richard MacCutchan 7-Dec-18 10:33am    
Thanks, he has moved to a new website - answer updated.
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:

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

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

// create and assign variables
string StudentInformation = "Student Information";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900