procedures and functions

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2007
Posts: 266
Reputation: quintoncoert is an unknown quantity at this point 
Solved Threads: 3
quintoncoert quintoncoert is offline Offline
Posting Whiz in Training

procedures and functions

 
0
  #1
Jul 6th, 2007
is there any way that one can place code in C# in a procedure or a function? I have code logic which is going to be executed many times over and instead of recoding it twenty times over I want to put them in functions and procedures so that I can just invoke them all the time. The help file only refers to procedures and functions in server 200 or later. is there not someting in c# itself?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: procedures and functions

 
0
  #2
Jul 6th, 2007
90% of what you do in C# (or any OO language for that matter) is in functions.

I am not sure exactly what you are asking though - I know you are new to C#. You ask if you can put some repetative code in a function and call it over and over instead of coding it everytime. But coding it every time is writing a function every time and calling that code is calling a function - so it is the same principal in c#.

If you could be a little bit clearer or give some small code of what you are trying to do I will give you a better answer to get you on your way.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 266
Reputation: quintoncoert is an unknown quantity at this point 
Solved Threads: 3
quintoncoert quintoncoert is offline Offline
Posting Whiz in Training

Re: procedures and functions

 
0
  #3
Jul 6th, 2007
consider the following c++ code. It contains a function called square wich can be called hundreds of times without the programmer having to code it one hundred times. main calls it only once but main could have called it as often as it wished.

int square( int )

int main()
{
int number;
cin >> number;

cout << square( number ) << endl;

return 0;
}

int square ( int n )
{
return n * n;
}

i would like to know the C# counterpart of that. But i would be calling the square function from a command button on a form. In Visual Basic you can add a new module which can be either a function( i.e. return values ) or a procedure ( not return values ). Then when you click a button in VB you say ...Call procedure... in the event procedure of the button or if you want the output from a function you just assign the function to variable also somewhere in code. How do I do the equivalent in C#?

Thank you very much for your help.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,485
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: procedures and functions

 
0
  #4
Jul 6th, 2007
You code it exactly like you have written it

If you need to call it from a button, then in your button click handler you merely call the function and update the value wherever you need to (i.e. a textfield or whatever).

C# doesn't have "procedures" - only functions. Functions that do not return a value are declared as returning "void", like so
  1. public void someFunction(){
  2. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC