Post #2 Hello World!
Installing and Using C#: I'd recommend using Visual Studio Code. First let me explain how I installed it for me and then tell you how to install it. The way I did it is I simply typed Visual Studio Code in google and one of the first sites let's you install it. I then wrote the hello world program originally. I ran it and it gave me errors but also asked if I was using C#. It was smart enough to recognize the language. I think it popped up in the lower right of the screen. It still gave me errors but it was recognizing the C#. I had looked up and found a link which has everything you need to get Visual Studio to work with C#. I restarted and followed the instructions in the link. I'd recommend following the instructions in the link.
link:https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code#hello-world
Basic Instructions:
1. Install Prerequisites using links provided on website or looking them up
a. Visual Studio Code
b. .Net Core SDK
c. C# extension
2. Follow instructions titled Hello World:
a. Open a project
The Hello World Program is the most basic program for any programming language. Every language I've seen has had a Hello World Program. C# does too. C#'s Hello World is very similar to Java with a little variation. C# uses something called namespaces. From what I can tell you so far they are basically a way to access the .Net Framework so that you can use types in the .Net Framework's system and so that you can keep track of types with a unique name. There are two of these in the Hello World Program. One is used to access the .Net Framework's system as I stated above. The other is around the program itself and has the name HelloWorld. The rest of the program is very similar to Java. There's a class that inside it has C#'s main method and then inside that is a print statement. The print line is not that different from Java. C# and Java did start off similar so it's not entirely surprising this program is pretty much the same.
link:https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code#hello-world
Basic Instructions:
1. Install Prerequisites using links provided on website or looking them up
a. Visual Studio Code
b. .Net Core SDK
c. C# extension
2. Follow instructions titled Hello World:
a. Open a project
- Open Visual Studio
- Go to explore then click Open Folder
- Select File > Open Folder > Select Folder
- Go to View > Terminal
- type in terminal dotnet new console
- This will actually create a Program.cs file in your folder, give you the "Hello World" program, along with a Project file HelloWorld.csproj.
- type dotnet restore. This will allow you to access .Net Core Packages needed to build projects.
- type dotnet run
The Hello World Program is the most basic program for any programming language. Every language I've seen has had a Hello World Program. C# does too. C#'s Hello World is very similar to Java with a little variation. C# uses something called namespaces. From what I can tell you so far they are basically a way to access the .Net Framework so that you can use types in the .Net Framework's system and so that you can keep track of types with a unique name. There are two of these in the Hello World Program. One is used to access the .Net Framework's system as I stated above. The other is around the program itself and has the name HelloWorld. The rest of the program is very similar to Java. There's a class that inside it has C#'s main method and then inside that is a print statement. The print line is not that different from Java. C# and Java did start off similar so it's not entirely surprising this program is pretty much the same.
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Now for the code. As I had stated there are two namespaces used.
using System; which allows access to the .Net Framework System. Required for all
programs in C#.
programs in C#.
namespace HelloWorld which surrounds the program and helps insulate your code. A name
is a name is a name.
is a name is a name.
The rest is almost the exact same as Java.
class Program is just a class. You can call it whatever you want.
static void Main(string[] args) is the basic main method for C#.
A special note on that, C# has four different main methods.
This specific one is C#'s equivalent to the Java main method.
Console.WriteLine("Hello World!"); is C#'s print statement, similar to Java.
Extra note: There is more on namespaces but I haven't gotten there yet. Console. is
required before WriteLine.
Resouces: I have gained some resources.
Started with MICROSOFT VISUAL C# .NET by Mickey Williams
Added C# PROGRAMMING BASICS FOR ABSOLUTE BEGINNERS by NATHAN CLARK
Added The C# Programming Language Fourth Edition by Anders Hejlsberg, Mads Torgusen,
Scott Wiltamuth and Peter Golde
required before WriteLine.
Resouces: I have gained some resources.
Started with MICROSOFT VISUAL C# .NET by Mickey Williams
Added C# PROGRAMMING BASICS FOR ABSOLUTE BEGINNERS by NATHAN CLARK
Added The C# Programming Language Fourth Edition by Anders Hejlsberg, Mads Torgusen,
Scott Wiltamuth and Peter Golde
I may be getting a little ahead of what you have learned so far, but what are the purposes for the four different main methods? Why would you use a different main method?
ReplyDeleteFirst let me explain the basic. Most languages have a main method which is always your starting point. You are ahead of what I've learned but essentially they do different things. The one we know about is the static void Main(string[] args) method. I'm going to paraphrase MICROSOFT VISUAL C# .NET by Mickey Williams. This method returns no value and accepts command-line parameters. The next static int Main(string[] args) returns an integer and accepts command-line parameters. This static void Main() returns nothing and does not accept command-line parameters. Last static int Main() returns an integer and has no command-line parameters. They all have different purposes but it seems to depend on what you want the main method to do. You'd use a different main method if you wanted to change what it does basically. This is a weird little thing but you can also have multiple main methods though it is unnecessary. You would need to specify which method is the starting method. You are ahead of where I am but you helped me mention something interesting about my program so thanks.
Delete