CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    50

    function and procedure handling in console program?

    how to?
    session™
    //Developing the Future
    //Power of the Vision

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    which procedure ? which function to handle ?
    well atleast elaborate your question ?

    Paresh
    - Software Architect

  3. #3
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    50
    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
    session™
    //Developing the Future
    //Power of the Vision

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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
    - Software Architect

  5. #5
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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
    - Software Architect

  6. #6
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    50
    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?
    session™
    //Developing the Future
    //Power of the Vision

  7. #7
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    hm... are you joking???

  8. #8
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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(...)
    {

    }
    }
    }

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

    and somewhere in your program
    you can use,

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





    Hope this helps,
    -Paresh
    - Software Architect

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