Click to See Complete Forum and Search --> : function and procedure handling in console program?


session
June 5th, 2003, 07:29 PM
how to?

pareshgh
June 6th, 2003, 12:20 AM
which procedure ? which function to handle ?
well atleast elaborate your question ?

Paresh

session
June 6th, 2003, 03:14 PM
private void MyMethod1()
{
// code here
}


private int MyMethod2()
{
// code here
return myInteger;
}

// To call the above methods:

MyMethod1();

// And for the second, it returns an integer,
// so you must assign a value for the return.
int returnValue = MyMethod2();



how to do this in console

pareshgh
June 6th, 2003, 03:27 PM
ok first tell me one this , have you successfully created console application !!! it doesn't need to have a VS.NET for creating projects

you can just copy following in some.cs file and compile it with
csc some.cs

-----------------some.cs-----------
using System;

namespace SomeApplication
{
public class SomeClass
{
private int a=10;
private int MyMethod()
{
return a;
}
static void Main(string[] args)
{
SomeClass oSC = new SomeClass();


Console.Write(oSC.MyMethod().ToString());
}
}
}

------------------------------------


Paresh

pareshgh
June 6th, 2003, 03:29 PM
forgot to mention that basically
main is a static method,
you can't execute a non-static method within a static method of a class or other class directly,
for that you need a object.
that's why you instantiate the object of same class within the static method which is Self Executing or Entry point of the exe.

Paresh

session
June 6th, 2003, 10:06 PM
oh well, i did successfully create console app... i use vs 2003... there's a selection when you create project. but how to use functions/precedures?

MartinL
June 7th, 2003, 11:51 AM
hm... are you joking???

pareshgh
June 9th, 2003, 10:49 AM
if you want to create and automate the methods and classes add members,
then

you go to ClassView and right click.
you will get the options there.

you can't add your manuall , standalone functions or procedures (as it happens in traditional procedural programming) in C# or in other OOP accept C++ which allows direct function calls because of backward compatibility.

well if you want to achieve that then
you can create (singleton) static methods and place it in your Utility namespace
so that you can call. just like Math class methods.

for example,

namespace Utility
{
public class ProvideMethods
{
public static int DoMySpecialWork(...)
{
:D
}
}
}

------------------
in your program do,
using Utility;

and somewhere in your program
you can use,

int nAnswer = ProvideMethods.DoMySpecialWork(...);





Hope this helps,
-Paresh