0

Что то не могу понять что делаю не так. Как вызвать After в main Нужно, чтобы отображались строки af и asd в main

Нужно примерно вот так чтобы в main было:

static void Main(string[] args)
        {
            Console.WriteLine(af + Environment.NewLine + asd);
            Console.ReadLine();
        }
public static void After(string af, string asd)
    {
        if (!af.EndsWith("123"))
        {
            if (asd.StartsWith("456"))
            {

            }
        }
    }
6
  • static void Main(.....bla bla) { After("string1", "string 2"); } 1 апр 2018 в 12:17
  • @MichaelVaysman а что с ним не так?
    – Rolly
    1 апр 2018 в 12:17
  • After(af, asd); прописал вот так, подчеркивает af, asd
    – Rolly
    1 апр 2018 в 12:20
  • Так они же у вас в Main не определены :) 1 апр 2018 в 12:21
  • 1
    Во первых, в Main не добавляют в ручную параметры. Давайте так, вы хотите параметры в командной строке давать или считывать откуда-то? 1 апр 2018 в 12:23

1 ответ 1

2

Можно например вот так:

static string af="123456";
static string asd="456789";

static void Main(string[] args)
{
    Console.WriteLine(af + Environment.NewLine + asd);
    After(af, asd);
    Console.ReadLine();
}

public static void After(string af, string asd)
{
    if (!af.EndsWith("123"))
    {
        if (asd.StartsWith("456"))
        {

        }
    }
}

Или, например вы передаете параметры при запуске exe, типа C:\myProgram.exe 123456 456789

static void Main(string[] args)
{
    string af = args[1];
    string asd = args[2];
    Console.WriteLine(af + Environment.NewLine + asd);
    After(af, asd);
    Console.ReadLine();
}
public static void After(string af, string asd)
{
    if (!af.EndsWith("123"))
    {
        if (asd.StartsWith("456"))
        {

        }
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.