I Tried To Not Follow The Workspaces And Other Stuff

In the workspaces I can only see languages HTML, CSS, Javascript and Python. I want to run C# there so I decided to do something different which was to name my files a .cs file. But my code doesn’t work:


.
Also why doesn’t Codecademy in the Learn C# course use _ for names like I was used to when I learnt Python.

Also the Learn C# course currently hasn’t explained why there is this:
using System;
or even this:
namespace hello_world
or this:
class program
or this:
static void Main(string[] args)
.
Also I don’t really know what those things really do or I don’t understand it.
This is my biggest wonder right now in C#. I am currently 28% through the course but it doesn’t even explain!

It will. They are concepts which are more ingrained in OOP side of C#, which will come later. Essentially, using System is similar to an import statement (except that it is a namespace-I’d recommend reading all of that article, as it explains namespaces far more proficiently than I every could) in that is says the C#, this program will be using the methods are classes in System, which include Console.WriteLine().


namespace hello_world says to the compiler that the current class (class program, I’ll get to that shortly), is within a namespace (like System, but different) called hello_world.


class program creates a class called program. Classes in C# work much like they do in Python, except in C# (pretty much) everything needs to be in a class.


static void Main(string[] args) creates a static void (or rather a function that returns void, or nothing) called Main, which accepts one argument; a string array (like a list in Python, but it can only store strings and has a set length; you’ll learn about them later in the course). In C#, for a program to actually run in the console, it has to have the function. Again, you’ll learn more about this later in the course.


That is because in C#, the naming convention is camel case (camelCase), where the first letter of every word (apart from the first word) is capitalised. In Python, the name convention is snake case (snake_case), where there’s an underscore between words.


That’s probably because the compiler in the workspace isn’t setup for C#, so naming the file .cs won’t make the compiler run it.

2 Likes

What’s static? What about I learn it later. I am 40% through the course.

static means the method can be called directly from the class itself, rather than from an instance of it. You will learn about it later in the course.

1 Like

It did, I’m at 75 % and I’ve learnt about these things:
Data Types And Variables,
Logic,
Conditionals,
Methods,
Arrays,
Loops,
Classes,
Objects,
Interfaces
and
Inheritance.