Status
Not open for further replies.

litewarez

Active Member
1,367
2008
1
0
heya guys, i need some help in C#

Recently been learning it as you know but heres the problem i have

When Using Visual Studio how do i create a small application and execute it within the CMD Area.

Because it starts with a "Form" as basic.

If you can just let me know how to create a simple hello world application and execute it within CMD as an exe would be HUGE Help :)

Thanks in advanced
 
30 comments
Sniper, you're an idiot for saying that no offense. You do realize they both use Win32 under the hood? And that you can do the exact same stuff with C# as you would with C++ but with less code? Seriously...

@Lite, as others said, create a console application.
 
lmfao @sniper. here - ill make one for you.

PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            DoWork("hello world.");
        }

        static void DoWork(string input)
        {
            Console.WriteLine(input);
            Console.WriteLine("hello again!");
            Console.Read();
        }
    }
}
 
Ok net me just get this straight.

void = does not return anything
the function Main is a constructor.
Console.WriteLine sends text to the CMD
Console.Read() waits for a user input. ?

and no matter the class named Program is executed first ?
 
indeed.

you can also do:

PHP:
static object[] myObject(string input)
{
// blah blah
// do some stuff
return new object { "some", "stuff", "here" };
}

static void hello()
{
object[] myNewObject = myObject("testing");

int test = myNewObject.Length; //get the size of the array
string a = myNewObject[0];
string b = myNewObject[1];
string c = myNewObject[2];
}
 
void = returns nothing
Main = the program's "entry point" (where the execution begins)
Read(); = reads a char and pause the console preventing it from instantly closing
Static = members/functions are accessible globally without having to new up an instance of the class
 
ok but do the objects HAVE to be static ?

in PHP This means that the object does not need to be initiated but you cant use the special variable $this / this ??

hyper Answered :) thanks all, im getting there xD
 
You can use 'this' but not to access static members. And only the programs entry point is required to be static. The rest is up to you.

PS: msdn.com
 
ya static = method thats not able to be called from an "instance".

PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Litewarez
{
    class Program
    {
        static void Main(string[] args)
        {
            object Output = new Output(); /*Just learning multiple objects*/
            Output.Send("This is a test"); /*This i expect to work be C# sharp goes nooo noo no*/
        }
    }

    class Output 
    {
        public void Send(string Text)
        {
            Console.WriteLine(Text);
        }
    }
}

Heres the error, i have tried myself so please don't be like bitch gtfo. :( i <3 you for helping xD

'object' does not contain a definition for 'Send' and no extension method 'Send' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
 
no, static has nothing to do with the class. What you describe is a 'sealed class'.

Also:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Litewarez
{
    class Program
    {
        static void Main(string[] args)
        {
[B]            Output op = new Output(); /*Just learning multiple objects*/
            op.Send("This is a test"); /*This i expect to work be C# sharp goes nooo noo no*/[/B]
        }
    }

    class Output 
    {
        public void Send(string Text)
        {
            Console.WriteLine(Text);
        }
    }
}

I suggest you read a good eBook first. You don't fly a plane without knowing how to fly.
 
See now Output op = new Output(); to me is pointless, it should automatically know that what object it is from the call.

Would you do

OtherOutput oop = new Output(); ??

yea i have a lot of books but i cant read :( xx
 
[type_name] [var_name] = new [type_name];

Don't try to apply PHP rules to C#. PHP is a dynamic language, C# a strongly typed one (meaning there is type safety). Again, ebook ;).
 
No Hyperz, i wasn't trying to think like PHP on this bit, im just saying it seems Pointless to have.

[type_name] [var_name] = new [type_name];

because C# should know the type_name from the new [type_name] i don't get why we have to wrtie the object name 2 times as your only assigning a reference to a variable :/

Having:

[var_name] = new [type_name];

yype_name should already know its an instance of Output.

Theres more than likly a perfect excuse as Obv the main C# guys are way advanced i just don't know the reason why.. then again EBOOK loool

Thanks for the info tho! :)

Also my first bit of C# xD

PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Litewarez
{
    class Program
    {
        
        static void Main(string[] args)
        {
            Output Output = new Output();

            //Ask the Question
            Output.Send("Please Enter your name");

            //Get the name
            var name = Output.ReadInput();

            //Clear the screan from "login xD"
            Output.Clear();

            //Send a welcome message
            Output.Send("Welcome: " + name);

            //Chill out!
            Console.Read();
        }
    }

    class Output 
    {
        public void Send(string Text)
        {
            Console.WriteLine(Text + "\n");
        }
        public void Clear() 
        {
            Console.Clear();
        }
        public string ReadInput() 
        {
            return Console.ReadLine();
        }
    }
}
 
Again, C# is NOT a dynamic language. http://en.wikipedia.org/wiki/Type_safety

These are all the very basics. That's why I keep saying read an ebook. If you're not willing to do that you're never gonna be good at it. Asking us for help here and reading a tut here and there will not get you far. I know I might sound a bit harsh here but that's how it is. What you're asking here now is something that gets explained in the first pages of any good eBook.

And again, when dealing with C#, forget you ever learned PHP because you'll get confused trying to apply scripting logic to programming logic.
 
I was just about to post the same thing. You should really start out with the basics before coding anything serious lol :D

EDIT: If you can't find a good eBook PM me Ill try and get the one I had in college.
 
Status
Not open for further replies.
Back
Top