As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

C# Programming, anything important to know?

Soviet WaffleSoviet Waffle Registered User regular
edited August 2007 in Help / Advice Forum
Well, I just started my C# programming class at CC, and it's my first time learning a programming language (It's an intro class, but I skipped the recommended class to fit my schedule.) Is there anything difficult or anything important I should know about this language? I know about the other C languages, but, nothing about C#

League of Legends: Studio
Soviet Waffle on

Posts

  • Options
    CaswynbenCaswynben Registered User regular
    edited August 2007
    It is 100 times more elegant than C and a lot more powerful than C++. Welcome to programming nirvana.

    Caswynben on
  • Options
    cyphrcyphr Registered User regular
    edited August 2007
    Caswynben wrote: »
    It is 100 times more elegant than C and a lot more powerful than C++. Welcome to programming nirvana.
    foreach makes me shed a little tear of joy every time I use it.

    cyphr on
    steam_sig.png
  • Options
    Soviet WaffleSoviet Waffle Registered User regular
    edited August 2007
    Awesome
    Thanks for letting me know I made a good choice

    Soviet Waffle on
    League of Legends: Studio
  • Options
    HeirHeir Ausitn, TXRegistered User regular
    edited August 2007
    The only thing I'll say about C# is that it's hard to learn that first, and then move on to something else. Mainly because you get so spoiled with .NET. :)

    Heir on
    camo_sig2.png
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited August 2007
    C# is a great language. It's part of the .NET framework, which will come to know very well. .NET provides you with tons of class libraries to quickly create powerful applications.

    I reccomend bookmarking the MSDN library, which documents all of these class libraries and is pretty easy to search around (get the client-side version if you can, I think it costs money but it's way faster).

    *edit* I don't know about hard to learn. I think that the .NET framework and application structure is actually the hard part to learn (or get used to, I should say). C# has a very clean and logical syntax as opposed to VB.NET.

    Jasconius on
  • Options
    JaninJanin Registered User regular
    edited August 2007
    Well, I just started my C# programming class at CC, and it's my first time learning a programming language (It's an intro class, but I skipped the recommended class to fit my schedule.) Is there anything difficult or anything important I should know about this language? I know about the other C languages, but, nothing about C#

    This advice won't make much sense to you until you've had a few classes, but remember that it's always better to return than to mutate. The more variables your class has, the worse it's designed.

    What this means is, do not write code like this:
    class MyClass
    {
    	int first, second, result;
    	void multiply ()
    	{
    		result = first * second;
    	}
    
    	void print2By2 () // Example
    	{
    		first = 2;
    		second = 2;
    		multiply ();
    		Console.WriteLine (result);
    	}
    }
    

    Instead, write it like this:
    class MyClass
    {
    	int multiply (int first, int second)
    	{
    		return first * second;
    	}
    
    	void print2By2 () // Example
    	{
    		int result = multiply (2, 2);
    		Console.WriteLine (result);
    	}
    }
    

    Janin on
    [SIGPIC][/SIGPIC]
  • Options
    AndorienAndorien Registered User regular
    edited August 2007
    Caswynben wrote: »
    It is 100 times more elegant than C

    This is true.
    ...and a lot more powerful than C++.

    Not quite so true.

    Andorien on
  • Options
    moebius206moebius206 Registered User new member
    edited August 2007
    For the record, foreach exists in most popular languages.
    cyphr wrote: »
    Caswynben wrote: »
    It is 100 times more elegant than C and a lot more powerful than C++. Welcome to programming nirvana.
    foreach makes me shed a little tear of joy every time I use it.

    moebius206 on
  • Options
    moebius206moebius206 Registered User new member
    edited August 2007
    If you're familiar with c/c++, then c# should be an absolute breeze.

    Honestly, the closest analog to c# is java. I have taken code from java and made only minor syntax changes and had it execute perfectly (which is also a tribute to good design).

    I can't really give you any tips on learning it other than take your time and just dig in. Like any other language, start with small problems and work your way up - don't rush into building a complicated app. There's a reason why all books start with hello world :)

    If you're not a novice to programming, and looking for some design tips, I'd definitely encourage you to look at a lot of the java packages that have been ported. I'm not a java snob (rarely use it), but all of the best libraries I use are ports. Let's face it, they've had time to mature. Examples: Spring.Net, NHibernate for the web arena.
    Well, I just started my C# programming class at CC, and it's my first time learning a programming language (It's an intro class, but I skipped the recommended class to fit my schedule.) Is there anything difficult or anything important I should know about this language? I know about the other C languages, but, nothing about C#

    moebius206 on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited August 2007
    jmillikin wrote: »

    Instead, write it like this:
    class MyClass
    {
    	void multiply (int first, int second)
    	{
    		return first * second;
    	}
    
    	void print2By2 () // Example
    	{
    		int result = multiply (2, 2);
    		Console.WriteLine (result);
    	}
    }
    

    You could also make multiply a variable itself and make the code even shorter:
    int multiply(int first, int second)
        {
            return first * second;
        }
    
    void main()
        {
            Console.WriteLine(multiply(2, 2));
        }
    

    This way you don't have to declare the variable and set the value to the result of the function.

    The function itself returns the variable and you can pass it off into whatever you need to use the result in.

    multiply() is now data typed and can be called anywhere you would insert an integer.

    Soviet, are you using C# for windows application development, or web application development?

    Jasconius on
  • Options
    ZxerolZxerol for the smaller pieces, my shovel wouldn't do so i took off my boot and used my shoeRegistered User regular
    edited August 2007
    C# as a language isn't anything particularly new or mindblowing. It's great and elegant, sure. But the goodies are exposed in the the .NET libraries. It was almost trivially easy for me to write a tool to synchronize my domain's Active Directory user list with an external database in C#. With Windows Forms, I don't want to look at MFC or the Windows API and message pumps ever again. It's wonderful stuff.

    Zxerol on
Sign In or Register to comment.