-
April 30th, 2007, 09:40 AM
#1
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#?
-
April 30th, 2007, 10:18 AM
#2
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 =-
-
April 30th, 2007, 01:31 PM
#3
-
April 30th, 2007, 03:10 PM
#4
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)
-
April 30th, 2007, 03:13 PM
#5
Re: Learning C sharp
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)
-
April 30th, 2007, 04:56 PM
#6
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?
-
April 30th, 2007, 05:54 PM
#7
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.
-
April 30th, 2007, 06:17 PM
#8
Re: Learning C sharp
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
-
April 30th, 2007, 06:27 PM
#9
Re: Learning C sharp
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
-
April 30th, 2007, 06:53 PM
#10
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.
-
April 30th, 2007, 07:03 PM
#11
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.
-
April 30th, 2007, 07:27 PM
#12
Re: Learning C sharp
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.
-
April 30th, 2007, 08:23 PM
#13
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.
-
April 30th, 2007, 09:26 PM
#14
Re: Learning C sharp
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.
-
May 1st, 2007, 12:07 AM
#15
Re: Learning C sharp
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|