CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 13 123411 ... LastLast
Results 1 to 15 of 181
  1. #1
    Join Date
    Mar 2007
    Posts
    375

    Thumbs up Learning C sharp

    Hey everyone! I recently moved from c++ to C# because i loved making windows applications. But i am having some problems (of course).

    i made this thread to ask questions about problems i might have. My first one is about fucntions (at least its called functions in c++)

    in c++ i could write a big block of code. f.eks.

    void error() {
    if(chances == 0) {
    cout<<"You have no more chances.";
    system("pause");
    close();
    }
    else{
    cout<<"The password is incorrect, please try again.";
    chances --;
    }
    }

    Now how would i create functions in C#?

  2. #2
    Join Date
    Jan 2006
    Location
    Baltimore, Maryland, USA
    Posts
    104

    Re: Learning C sharp

    To my understanding, what you mean by 'functions' are called 'methods' within C#. You would write them out the same way with return type, name, and arguements, but this 'method' would be located inside a particular class.

    I don't know if you use an IDE, but I use Visual Studio 2003 and when I start a new project, a skeleton structure is created for me. I can just add my own 'methods' and call them when needed. I suggest you just follow form with the skeleton code and you should be fine.
    -= the best is yet to come =-

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Learning C sharp

    I think if you come from C++ and have worked with MFC you should be familiar with classes, inheritance generally talked with OOP. Then its a small change in learning the syntax and the terminology of C# as it is pretty near to C++ altered a bit into the direction od VB I would suggest you the book Visual C# Step by step which is a Microsoft press book, easy to learn. Coming from C++ you will read it like a crime thriller or whatever you like to read for fun. Things are working a bit different to C++ there are pointers but they are easier in handling then in C++.

    BTW if you want to show code use codetags otherwise as you see its totally corrupted into an unreadable heap of letters, normally I called this codesausage

    jonny poet
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  4. #4
    Join Date
    Mar 2004
    Location
    Ukraine
    Posts
    170

    Re: Learning C sharp

    Well called methods is another name of functions in OOP their main difference is that calling methods are members of a class. But you already know it if you are working with C++.
    in C# you might begin with certian class like this
    Code:
      class Security
      {
       ......
       void error() {
       if(chances == 0)
       {
        MessageBox.Show("You have no more chances.")//or you may use
        throw new Exception("You have no more chances.")//ofcourse you may modify exception class to your needs
         system("pause");
        close();
        }
        else{
    MessageBox.Show("The password is incorrect, please try again.")
    chances --;
    }
    }
    In this example I have used winows boxes like messagebox but you may use Console.Add() to write to console
    So main Idea of C# not let functions being alone they need class.
    Another interesting thing that you may do next trick
    Code:
      class Myclass
      {
       ...........
       //Some members
       class MyInnerClass
            {
               //another members
              }
      }
    If you will have more specific questions ask and they will be answered
    God could improve essentially a
    human nature, but he
    was too anxious with compatibility
    with the monkey.
    (Eugeny Goldberg)

  5. #5
    Join Date
    Mar 2004
    Location
    Ukraine
    Posts
    170

    Re: Learning C sharp

    Quote Originally Posted by JonnyPoet
    Coming from C++ you will read it like a crime thriller or whatever you like to read for fun.

    jonny poet
    Yes it is
    God could improve essentially a
    human nature, but he
    was too anxious with compatibility
    with the monkey.
    (Eugeny Goldberg)

  6. #6
    Join Date
    Mar 2007
    Posts
    375

    Re: Learning C sharp

    Thanks for all the awesome replies ppl, but after a lot of testing, the only thing that worked was to put "static void *name*() { *code* }" in the class with the main fucntion in. i tried that loads of times, but without the "static" in front of it, and it didnt work without it.

    Next question: How can i add titles and icons to messageboxes?

    Next statement (=P): Here is the program i am making: MathMaker!!! If you wana know what it does, click "info" in the program :P its really cool, i promise you.

    If i may say so, i think its pritty good considering i have been learning C# for yust a few days. What do you guys think?

  7. #7
    Join Date
    Mar 2007
    Posts
    375

    Angry Re: Learning C sharp

    Another question:
    why doesnt this code work?
    Code:
    using System;
    using System.Windows.Forms;
    
    namespace Test
    {
    	class Test
    	{
    		private System.ComponentModel.IContainer components = null;
    		
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
            
    		private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.Text = "tomas";
            }
        }
    }
    Error:
    Code:
    <10,33>: error CS0115: 'Test.Test.Dispose(bool)': no suitable method found to override
    Last edited by dahwan; April 30th, 2007 at 06:05 PM.

  8. #8
    Join Date
    Mar 2007
    Posts
    274

    Re: Learning C sharp

    Quote Originally Posted by dahwan
    Next question: How can i add titles and icons to messageboxes?
    Just look at the available constructors for MessageBox.Show

    MessageBox.Show((listView1.SelectedItems[0].Text + " is already established for Shadowing!"),"Add User",MessageBoxButtons.OK,MessageBoxIcon.Warning);

    Here's one of mine with the text, title, ok button, and an icon

  9. #9
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Learning C sharp

    Quote Originally Posted by dahwan
    If i may say so, i think its pritty good considering i have been learning C# for yust a few days. What do you guys think?
    Great if you have learned a lot. But Please also learn that we never accept to download and open an exe file Your program Mathmaker is an exe file included in a zip file. If you want to show us what you have learned post the source code in a zip and add it to your post. I dont see any reason why to pay for Premium services at the link which you gave or to wait for downloading. At least it was wasted time as it is an exe file.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  10. #10
    Join Date
    Mar 2007
    Posts
    375

    Re: Learning C sharp

    why is it a waste of time since its an exe file? cant you open them? and btw, do anyone have an msn adress or something, so i can get ansvers a litle faster? i have problems often, and writing a short program would take days with this forum.

  11. #11
    Join Date
    Nov 2006
    Location
    North Bend, WA
    Posts
    487

    Re: Learning C sharp

    Have you ever heard the term "trojan"? How do we know your program won't start deleting files or screwing up the registry?

    As for your Dispose question, you didn't derive from IDisposable.

  12. #12
    Join Date
    Mar 2007
    Posts
    274

    Re: Learning C sharp

    Quote Originally Posted by dahwan
    why is it a waste of time since its an exe file? cant you open them? and btw, do anyone have an msn adress or something, so i can get ansvers a litle faster? i have problems often, and writing a short program would take days with this forum.
    What version of c#/vs are you using? express, standard, professional, etc?

    And by the way, I didnt even attempt to hover my mouse over your link.

    Post some screenshots of your program instead. I know I dont want any trojans.
    Last edited by Traps; April 30th, 2007 at 07:30 PM.

  13. #13
    Join Date
    Mar 2007
    Posts
    375

    Re: Learning C sharp

    Why should i trojan you!? i am a user at this forum yust wanting help. At the level of my skill, you should all know i am not near capable of making a trojan of any kind.

    How can i show you my program if all of you is too chicken to try it? i'll post a couple of screenie's so you guys can see it.





    well, what do you think? i swear to god that link is safe. yust follow it and download the program.

  14. #14
    Join Date
    Mar 2007
    Posts
    375

    Re: Learning C sharp

    Quote Originally Posted by Traps
    What version of c#/vs are you using? express, standard, professional, etc?

    And by the way, I didnt even attempt to hover my mouse over your link.

    Post some screenshots of your program instead. I know I dont want any trojans.
    I have Visual studio 2005, but i am using notepad for the codes and the SDK command prompt for compiling.
    Again i promise that my link is my dahwan mathMaker program, no trojan.

  15. #15
    Join Date
    Mar 2007
    Posts
    274

    Re: Learning C sharp

    Quote Originally Posted by dahwan
    well, what do you think? i swear to god that link is safe. yust follow it and download the program.
    Umm. Its a start . Here's my first program after a few days of c#

    Its a tabbed web browser, like ie7's dynamic tab's
    Last edited by Traps; May 1st, 2007 at 12:09 AM.

Page 1 of 13 123411 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured