-2

CS 5001: Program does not contain a static 'Main' method test_test suitable for an entry point.

The above error is given then I try to run the program along with an error attracted to the txt file call in the main stating:

there is no argument given that corresponds to the required formal parameter 'arr' of 'txt_program.txt(string[][])'

Furthermore the program is an console app with the following code for an item:

namespace text_test
}
class txt_program
    {
        public void txt()
        {
        string[] string1 = new string[] {"a", "a", "a" };
        string[] string2 = new string[] { "b", "b", "b" };
        string[] string3 = new string[] { "c", "c", "c" };

        string[][] names = new string[][] { string1, string2, string3 };

            using (StreamWriter SW = new StreamWriter(@"txt.txt"))
            {
             for (int i = 0; i < 3; i++)
            {
                for (int a = 0; a < 3; a++)
                {
                    Console.Write(" " + arr[i][a]);
                }
                Console.WriteLine();
                }
            }
        }
    }
}

The above code is called in the main by using the following code:

namespace text_test
{
class Program
{
    static void Main(string[][] args)
    {
    new txt_program().txt();
    }
}
}

The wished output is a textfile looking like the following:

a a a
b b b
c c c
  • 3
    `string[][] args` in your `Main` method should be `string[] args`. It's not clear what you mean by "then I run the program" - given that it hasn't compiled, how are you running it? – Jon Skeet Sep 14 '16 at 13:29
  • @JonSkeet I changed it to 'then I try to run the program', because it does not run due to the errors. – Erik Lenstrup Sep 14 '16 at 13:34
  • Well yes - although the problem you reported of "there is no argument given that corresponds to the required formal parameter 'arr' of 'txt_program.txt(string[][])'" wouldn't be presented, as your `txt()` method doesn't *have* any formal parameters. – Jon Skeet Sep 14 '16 at 13:36
  • works fine for me, only error i found was that inside the for loop instead of Console.Write(" " + arr[i][a]); it should be Console.Write(" " + names[i][a]); I mean you dont have an "arr" called array after all, the one you want to draw the data from is called "names" – Innat3 Sep 14 '16 at 13:37
  • @JonSkeet ahhh okay I see – Erik Lenstrup Sep 14 '16 at 13:41
  • @JohnsonKinggerly: Well that's a *separate* problem. It sounds like to be honest, you'd be better off starting with a blank sheet of paper, so to speak. Create an *empty* console app which compiles, and gradually add code to it, repeatedly compiling it. Stop as soon as there's a problem, and fix it. I'd also strongly advise you to start following .NET naming conventions (and code indentation) too. – Jon Skeet Sep 14 '16 at 13:44
  • @JonSkeet I found the problem. It was due to ekstra spacing in the string. Fore some reason it did not like that. – Erik Lenstrup Sep 14 '16 at 14:40
  • @JohnsonKinggerly: I don't know what you mean by "extra spacing in the string" but the root of the immediate problem in the code you showed was due to having an extra `[]` - nothing to do with spacing. – Jon Skeet Sep 14 '16 at 14:45

1 Answers1

0

Some issues....

"there is no argument given that corresponds to the required formal parameter 'arr'" You have no variable declared named 'arr', did you mean to use 'names' here?

These

string[] string3 = new string[] { "c", "c", "c" };

You probably meant to do

char[] string3 = {'c','c','c'};

but even that is not nessisary, just use

string string3 = "ccc";

Strings are just char arrays already so you can do

string string3 = "abc";
string3[2] == 'c'; (true)

for this

string[][] args

You probably should have

string[] args

but you never access args here so its not necessary for the code you provided.

For your startup issues right click the project and in the Application tab of visual studio under startup object you should have 'text_test.Program' selected in the drop down.

Paul Swetz
  • 2,234
  • 1
  • 11
  • 28