Question does not contain a static Main method?

old_man

Member
Joined
Oct 24, 2016
Messages
17
Location
Michigan USA
Programming Experience
Beginner
This is a very simple code, I just can get it to work:


using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Net;

static void Main(string[] args)
{
   var client = new WebClient();
   var url = "http://www.gametrailers.com";
   Console.Write(client.DownloadString(url));
   Console.ReadKey();
}




The error is this: "does not contain a static Main method"

I hope someone can point me in the right direction, to get this to work.

You can see I would like to build bots.:concern:
 
Last edited by a moderator:
This code works without error. The code that you have pasted does not include a namespace or class. The Main(string[] args]) method is an entry point; it must be within a class.
 
It looks like you're just copying and pasting code from the web without any understanding of how a C# application works. I suggest that you create a new C# Console application project and then LOOK at the code. You'll see that a Program class is generated and it has a Main method. That is the entry point for the application. You can then place code INSIDE that method.
 
You are so right i found this at a c# website. But i don't see the problem with that, I should learn a lot making it work.
Ok let start I don't know c# but I been programming in basic for about ten years, I made many games in that. I did some programming vs-basic and a little in c.
I thing you are talking about this line of code:
static void Main(string[] args)
Should I put something in the args of the main? is that what you are talking about?
 
You are so right i found this at a c# website. But i don't see the problem with that, I should learn a lot making it work.
Ok let start I don't know c# but I been programming in basic for about ten years, I made many games in that. I did some programming vs-basic and a little in c.
I thing you are talking about this line of code:
static void Main(string[] args)
Should I put something in the args of the main? is that what you are talking about?
I'll give you a nudge, in C# just like in vb/vb.net in order to have a method you first need to have a class. Right now you have a method called main, is it in a class?

Also C# is much more picky about things being in a Namespace, which vb.net is more relaxed about, but your class once made should reside in a Namespace, typically being the project's name.
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


//This is using the System namespace and accessing the Net namespace
using System.Net; // This is you needed import for the WebClient


namespace Testing // This is a namespace - This is optional, but recommended (I called it testing, but could be anything so long as it doesn't conflict with the .net framework)
{


    class Program // This is a class - You need this
    {
        static void Main(string[] args) // This is the 'main' method - it is an entry point for all c# programs
        {


            var client = new WebClient();
            var url = "http://www.gametrailers.com";
            Console.Write(client.DownloadString(url));
            Console.ReadKey();


        }


    }
}



This is what your program should look like.

The 'experience' that you have seems odd considering that any intro to c# would have cleared all this up for you.

I have posted some c# resources here:
HTML:
http://www.csharpforums.net/programmer-chat/3146-c-difficult-beginner-language.html
 
Last edited:
Should I put something in the args of the main? is that what you are talking about?

No, what I'm talking about is what I actually said. If you want code executed then put it inside the Main method. Inside a method means between the braces that follow the method declaration. That 'args' parameter will contain the commandline arguments that you pass when you execute the EXE.
 
ok, I signed up for a c# class, plus I found a nice videos course at a place called ch 9 c#.
I change the code around just play with it and it still works.

Thank you for your help, I am sure you will see a lot of me as I get deeper into C#

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


//This is using the System namespace and accessing the Net namespace
using System.Net; // This is you needed import for the WebClient


namespace MyScraper // This is a namespace - This is optional, but recommended (I called it testing, but could be anything so long as it doesn't conflict with the .net framework)
{


    class test_program // This is a class - You need this
    {
        static void Main(string[] args) // This is the 'main' method - it is an entry point for all c# programs
        {


            var client = new WebClient();
            var url = "http://www.gametrailers.com";
            Console.Write(client.DownloadString(url));
            Console.ReadKey();


        }


    }
}
I see what class and namespace is.
old man
 
Back
Top Bottom