how to?
Printable View
how to?
which procedure ? which function to handle ?
well atleast elaborate your question ?
Paresh
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
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
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
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?
hm... are you joking???
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