Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMarcelo Castillo
Courses Plus Student 1,747 Pointsi dont understand what was explained in this video
in this video c# classes and static voids were explained i dont understand it can some one please help me understand?
3 Answers
Damien Watson
27,419 PointsHi Marcello, Is there anything in particular that didn't make sense, or just everything?
The code displayed in the video looks like this (I just like to have my bracket on the same line as the definition - both are valid):
class Program {
static void Main() {
}
static void Other() {
}
}
The breakdown of this is:
class yourClassName {
accessibleLevel returnType runThisMethodFirst() {
}
accessibleLevel returnType anotherMethod() {
}
}
'accessibleLevel' - He will explain the 'static' I'm sure, but the basic explanation is that this makes the method accessible from outside the class. It's a bit more involved but thats the basic of it.
'void' means nothing is returned. Other valid types include strings, integers etc.
An example might look like this:
class Program {
static void Main(string name) {
string hello = "Hello " + name;
}
static string HelloThere(name) {
return "Hello there " + name;
}
}
I hope this has helped, I'm a bit of a c# noob.
Seth Reece
32,867 PointsHi Marcelo,
You will gain a better understanding as you progress through the course. Classes are objects. E.g. if you where making a game, you could have classes for a Monster, and a Player. The static keyword allows the method to be called without instantiating an instance of the class. The keyword void means that the method doesn't return anything.
Ben Morse
6,068 PointsA class is a binding of methods and variables in a single unit. An object is an instance of a class.
What they are going over here is like the introduce of classes. Classes contains methods, which tells the program to do something when called upon, and it will have its own set of variables that contain some sort of value for that class.
Think of it as creating a class for Cats. It methods are its actions(sleep, eat, annoyMaster) and its variables are what visual details(fuzz, big) the represents a cat.