O
O
Oleg_Danilov2014-07-24 20:40:53
Programming
Oleg_Danilov, 2014-07-24 20:40:53

How to solve problems in source code?

Greetings!
I would like to ask:
1) Why is only one result displayed? (Hello Jo only)

using System;

class A
{
    static void WriteHelloJo()
    {
        Console.WriteLine("Hello Jo");
        Console.ReadLine();
    }
    static void WriteHelloSam()
    {
        Console.WriteLine("Hello Sam");
        Console.ReadLine();
    }
    static void WriteHelloYou()
    {
        Console.WriteLine("Hello You");
        Console.ReadLine();
    }
    static void Main()
    {
        WriteHelloJo();
        WriteHelloSam();
        WriteHelloYou();
    }
}

2) The compiler throws an error: "A get or set accessor expected". How to fix the error and why does the compiler output it?
using System;

class A
{
    void WriteHello(string someName)
    {
        Console.WriteLine("Hello " + someName);
    }
            static void Main
            {
                WriteHello("Jo");
                WriteHello("Sam");
                WriteHello("You");
            }
}

In M. Dreyer's textbook "C# for schoolchildren" such examples are given. But what is good about this textbook is that everything is simply and clearly written here (from scratch). I will be grateful for the answers.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vdem, 2014-07-24
@Oleg_Danilov

1. Try [Enter] to press after the output of the first line.
2. No parentheses (UPD: parentheses) after the Main declaration.

O
Oleg_Danilov, 2014-07-24
@Oleg_Danilov

2)

using System;

class A
{
    static void WriteHello(string someName)
    {
        Console.WriteLine("Hello " + someName);
       
    }
    static void Main()
    {
        WriteHello("Jo");
        WriteHello("Sam");
        WriteHello("You");
        Console.ReadLine();
    }
}

one)
using System;

class A
{
    static void WriteHelloJo()
    {
        Console.WriteLine("Hello Jo");
    }
    static void WriteHelloSam()
    {
        Console.WriteLine("Hello Sam");
    }
    static void WriteHelloYou()
    {
        Console.WriteLine("Hello You");
    }
    static void Main()
    {
        WriteHelloJo();
        WriteHelloSam();
        WriteHelloYou();
        Console.ReadLine();
    }
}

D
Dmitry Aitkulov, 2014-07-25
@Scarfase1989

Read the Bible C# Flenov better, and preferably several times
There it is written in more detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question