Friday 19 September 2008

My first C# program

Well I've now read 3 hours of my teach yourself C# book.
I've found it really hard to keep awake, not learnt that much so far.
Taken me ages to motivate myself to keep going.

Anyways, I thought I'd try and write a small program to see how far I could go.
I'm stuck already, having difficulty creating a function, or what I'd think of as a function in vb.

I googled and found someone saying that you can't do functions in C#.

That seems weird.
So, I guess I'm a bit more motivated to read further in my book.
Otherwise I'll not be able to finish my program :(

by
JM

2 comments:

  1. You can have functions in C# but they're called methods and they always have to be members of a class, e.g.

    public class CMyClass
    {

    public int DoubleAnInteger(int X)
    {
    return 2 * X;
    }

    }

    To call it, you'd have to instantiate an object:

    CMyClass myObject;

    int Y = myObject.DoubleAnInteger(2);

    ReplyDelete
  2. I see.

    I guess it kind of makes sense that in a more C++ type language you'd use and destroy things.

    In VB we have modules which are sort of global and you don't have to instantiate and instance etc.

    So what do you do with your string functions, I assume you have them all in the same class?

    So you just instiate the class every time you want to use a string function?

    ReplyDelete