Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Just learning C#, probably common errors?


  • Please log in to reply
6 replies to this topic

#1 chromebuster

chromebuster

  • Members
  • 899 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:the crazy city of Boston, In the North East reaches of New England
  • Local time:12:32 PM

Posted 10 July 2010 - 10:06 PM

Hi folks,
as I have stated in other posts, my favorite language is C# (with many attempts from friends to try and turn me away from it), and so I want to take the initiative and read up on it so that I can learn and become efficient in it. I don't want to be a programmer as a career, so that's why I don't take programming in school. I'm no mathematician, so It'd be foolish for me to want to be a programmer as a career. I do however want to create programs for enjoyment. Well anyway, I was reading a particular book (Beginning Visual C# 2008), and I can't get past the Try it out on like page 3 or so. The objective is to write a simple console app that simply writes one line of text to the screen then terminates with a keypress. I am pretty sure that I wrote the following code correctly:
After the default template code:
{
Console.WriteLine("The first app in C# programming!");
Console.ReadKey();
}
}
}
I received the following error when pressing the F5 key to run:>filepath of executable>: file does not contain a static 'Main method suitable for an entry point. What does this mean? and the other unfortunate thing is the fact that the next time I opened VS 2010, my whole file was gone! Program.CS was nothing but a blank file! I'm assuming that was user error-generated in that I forgot to save. and finally, how on earth do you turn off UTF8 in VS? This guy who thinks he knows everything told me that UTF8 must be turned off for programs to run and compile properly. Any assistance on this would be great.

Many thanks,
Chromebuster

The AccessCop Network is just me and my crew. 

Some call me The Queen of Cambridge


BC AdBot (Login to Remove)

 


#2 strolln

strolln

  • Members
  • 400 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:N. Calif.
  • Local time:08:32 AM

Posted 10 July 2010 - 10:47 PM

You need some additional code. Try this:

// Namespace Declaration
	using System;

	// Program start class
	class WelcomeCSS
	{
		// Main begins program execution.
		static void Main()
		{
			Console.WriteLine("The first app in C# programming!");
			Console.ReadKey();
		}
	}

To Err is human; to really foul things up requires a Bleeping Computer!

#3 chromebuster

chromebuster
  • Topic Starter

  • Members
  • 899 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:the crazy city of Boston, In the North East reaches of New England
  • Local time:12:32 PM

Posted 11 July 2010 - 02:17 PM

Thanks. I'll have to try that. But strangely enough, when you select console application in the list of templates, that namespace is already declared. I think is't the first one in the file. Yep, right at the beginning there is using System; Using System.Generic; using System.collections;. You're saying that i need to add the Class WelcomeCSS to that? Where does that go in the source file? And what is the difference between the code you provided with StaticVoidMain(); and the default StaticVoidMain([args]);? If you could let me know. And what is the scoop on UTF8? Is that guy who told me that it has to be shut off correct?

Thanks,
Chromebuster

The AccessCop Network is just me and my crew. 

Some call me The Queen of Cambridge


#4 strolln

strolln

  • Members
  • 400 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:N. Calif.
  • Local time:08:32 AM

Posted 11 July 2010 - 06:35 PM

If the System namespace is already declared then you don't need it. You can name your class whatever you want, doesn't have to be called WelcomeCSS. As far as the 2 ways of declaring Main, the 2nd method with [args] is to allow for command line input arguments passed to the program. Additional code would be required to parse the arguments. Usage of UTF8 is dependent on whether you want to support Unicode in your program or not.
To Err is human; to really foul things up requires a Bleeping Computer!

#5 chromebuster

chromebuster
  • Topic Starter

  • Members
  • 899 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:the crazy city of Boston, In the North East reaches of New England
  • Local time:12:32 PM

Posted 11 July 2010 - 11:41 PM

Okay. I'll change the defaults then to say what class it is. But I don't necessarily get the difference between what is already given in the default template for console apps and what you added. And by the way, do you use Visual Studio or Visual Studio Express for your C# development? Maybe that's where the confusion lies? And thank you so much for clarifying the UTF8 thing. That proves that this guy really doesn't know what he is talking about and that he shouldn't be trying to provide support for users.

The AccessCop Network is just me and my crew. 

Some call me The Queen of Cambridge


#6 chromebuster

chromebuster
  • Topic Starter

  • Members
  • 899 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:the crazy city of Boston, In the North East reaches of New England
  • Local time:12:32 PM

Posted 12 July 2010 - 09:18 PM

Hi again,
I was able to figure out, ... I think, what was causing the error. I have both versions of Visual Studio, one on my laptop which is VS 2010 Pro per my Dreamspark membership, and the other which is on my desktop, which is Visual C# express 2010. I think the error was caused from my accidental use of the VB defaults instead of the C# ones. Do you know of any particular shortcuts on the keyboard I could use to change the default development settings in VS 2010 pro?

The AccessCop Network is just me and my crew. 

Some call me The Queen of Cambridge


#7 chromebuster

chromebuster
  • Topic Starter

  • Members
  • 899 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:the crazy city of Boston, In the North East reaches of New England
  • Local time:12:32 PM

Posted 11 September 2010 - 01:05 AM

Oops ... Never mind. I don't know what happened, just a goof-up on the part of Visual Studio I think.

The AccessCop Network is just me and my crew. 

Some call me The Queen of Cambridge





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users