C# Programming

>Hi

So in c#, I don't really understand how to call a Method (I think that's what it's called), it's kind of what a function is in JavaScript. Anyway, I was wondering how I call the method outside of the method. I think I call the method like this (without the angle brackets) - (); - If you know how to, please TELL ME!

Other urls found in this thread:

msdn.microsoft.com/en-us/library/system.reflection.methodinfo.invoke(v=vs.110).aspx
mva.microsoft.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-16169
twitter.com/SFWRedditGifs

var a=new SomeClass():
a.methodName();

Do I use 'var' or do I use like int, float, bool, string?

You can use both.

Its not working. This looks like JavaScript code.

Too bad.

do the needful

There are no 'global' methods that you can call just by it's time. If method belongs to some class then you make an object (an instance) of that class and call a method on that object like this poster said: Keep in mind that "var" is the name of the class

I don't understand what you me by this?

>Keep in mind that "var" is the name of the class
C# has type deduction.

If you're asking how to literally call a fucking method, then you should watch or read some introductory tutorial to this language. You can't go straight into writing code without knowing the most basic things.

>what are static methods?

>call a method outside of a method
You meant outside of a class? If you meant that you need to make that method static by simply inserting static before the name of the function and you should also make it public so that it's accessible from another class

class firstClass
{
public static void myFunction()
{ your code }
}

class secondClass
{
your code...
firstClass.myFunction() ;
...
}

>how I call the method outside of the method
msdn.microsoft.com/en-us/library/system.reflection.methodinfo.invoke(v=vs.110).aspx

Another approach to that is making an instance of that class
...
class secondClass {
static fistClass instance;
....
instance.myFunction();
}

Retarded answer for retarded question, eh?

I think you should look what "Object Oriented Programming" is.
After that you should be able to understand much more.

WHY ISN'T THIS WORKING ;,,,,(

namespace Think_Medieval
{

class Program
{

// Variables

int playerHealth = 100;

static void Main(string[] args)
{

Inventory();

Console.ReadKey();

}

public static void Inventory ()
{

Console.WriteLine("HP: " + playerHealth);

}

}

}

Error Code: CS0120
An object reference is required for the non-static field, method, or property 'Program.playerHealth'

(The second time I write playerHealth it has a red underline to it).

install gentoo

good job

static int playerHealth

Make playerHealth static

This. OP doesn't need a forum, they need a basics course.

Go watch mva.microsoft.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-16169

Then, if you still have problems, get back to us.

go read a book

>>Hi
why tf greentext this
>So in c#, I don't really understand how to call a Method (I think that's what it's called), it's kind of what a function is in JavaScript.
off to a good start
>Anyway, I was wondering how I call the method outside of the method.
> call the method outside of the method
oh lawdy
>If you know how to, please TELL ME!
CAPS
>There are no 'global' methods that you can call just by it's time.
>time
> If method belongs
if english bad
>Keep in mind that "var" is the name of the class
what the
>I don't understand what you me by this?
they me something alright
>class firstClass
>{
>public static void myFunction()
>{ your code }
>}
newfag
no comment
>Another approach to that is making an instance of that class
>...
>class secondClass {
>static fistClass instance;
newfagging continues
>WHY ISN'T THIS WORKING ;,,,,(
CAPS EMOTICON-UUU
>namespace Think_Medieval
>{
>class Program
>{
>// Variables
>(The second time I write playerHealth it has a red underline to it).
newfagging continues

I thought the C# devs couldn't be that bad, but damn. Someone post the obligatory handicap pic, looks like it's highly appropriate for this thread
or maybe it's the time of day when we get more posters from certain countries