A JeDi Journey (there is no certainty, only opportunity)

yesterday padawan will become tommorow jedi

Posts Tagged ‘c#

learning c# thru java part 1

with 2 comments

i found out very interesting facts while learning basic c#.

It took me about half an hour to identify what was wrong with my code below. It just that the main function problem.

namespace ConsoleTest //java guys: in java we call this thing packaging
{
    class Intro1
    {
        static void Main(string[] args) //java guys: watch out the main!!!! in c# its capital M
        {
            System.Console.WriteLine("hello worlds");
        }

    }
}

this is also a valid code as shown below

namespace ConsoleTest //java guys: in java we call this thing packaging
{
    class Intro1
    {
        static void Main() //java guys: huhu no argument from command line
        {
            System.Console.WriteLine("hello worlds");
        }

    }
}

Yeahh multiple main entry for 1 source file also permitted. Except when u compile the source file. U need to give extra information to the clr. As shown below.
example: csc filename.cs /main:whichClass.cp

namespace ConsoleTest //java guys: in java we call this thing packaging
{
    class Autobat
    {
        static void Main()
        {
            System.Console.WriteLine("autobat...transform");
        }

    }

    class Decepticon
    {
        static void Main()
        {
            System.Console.WriteLine("decepticon..kill em all!!!!");
        }

    }
}

And u should know that the exe file produced by the clr its not the same with other old exe files. This new exe file compiled by the clr needs the .net platform to run.
Also u cannot compile class with out the entry point (the main function). U need extra parameter to compile it.
example: csc /target:library namafile.cs

If u want, u can also have the same class name but in different namespace in the same source file. Also i learned that c# support alias which i doubt its usefulness.

Like java, c# can also have multiple class declaration in 1 source file. But java only permitted only 1 public class declaration for each class.

Written by peysal

April 26, 2008 at 6:59 am

Posted in SofTware DevelopMent

Tagged with , ,