O
O
Oleg_Danilov2014-07-15 23:38:27
Programming
Oleg_Danilov, 2014-07-15 23:38:27

Why does the compiler throw errors?

Hey!
I decided to read the book by M. Dreyer "C# for Schoolchildren" . Downloaded Microsoft Visual C# 2008 Express Edition as written. Read up to the topic "Declaring and calling a method" When typing the source code from the example into the ConsoleApplication template, the compiler generates two errors:
1. A namespace does not directly contain members such as fields or methods (13 line; 1 column)
2.Expected class, delegate , enum, interface, or struct (line 14; column 12)
Why does the compiler throw errors? How to solve the problem?

using System;

class Person
{
    public string firstName;
    public string lastName;
    public void ShowFullName()
    {
        Console.WriteLine("Name is" + firstName + " " + lastName);
    }
}

Person Petr;
Petr = new Person();
Petr.firstName = "Petr";
Petr.lastName = "Ivanov"
Petr.ShowFullName();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg_Danilov, 2014-07-16
@Oleg_Danilov

Working code:

using System;

class Person
{
    public string firstName;
    public string lastName;
    public void ShowFullName()
    {
        Console.WriteLine("Name is " + firstName + " " + lastName);
        Console.ReadLine();
    }
}

class A
{
    public static void Main()
    {
Person Petr;
Petr = new Person();
Petr.firstName = "Petr";
Petr.lastName = "Ivanov";
Petr.ShowFullName();
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question