How do you call a method from static main()?

I have a console application with a Main method and a function.

How can I make a function call from the Main method?

I know the code below won't work

static void Main(string[] args)
{            
   string btchid = GetCommandLine();// GetCommandline is a mthod which returns a string
}

Answers


There's also

var p = new Program();
string btchid = p.GetCommandLine();

Make the GetCommandLine static!

namespace Lab
{
    public static class Program
    {
        static string GetCommandLine()
        {
            return "Hellow World!";
        }

        static void Main(string[] args)
        {
            System.Console.WriteLine(GetCommandLine());
            System.Console.ReadKey();
        }
    }
}

You can change the function as a static and call it . Thats all.


static class Program
{        
    [STAThread]
    static void Main()
    {
        string btchid = Program.GetCommandLine();
    }

    private static string GetCommandLine()
    {
        string s = "";
        return s;
    }
}

A linear search approach to your problem:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinearSearch
{
class Program
{

    static void Main(string[] args)
    {
        int var1 = 50;
        int[] arr;
        arr = new int[10]{10,20,30,40,50,60,70,80,90,100};
        int retval = linearsearch(arr,var1);
         if (retval >= 1)
         {
           Console.WriteLine(retval);
           Console.Read();
         }
         else
         { Console.WriteLine("Not found"); Console.Read(); }
    }

    static int linearsearch(int[] arr, int var1)
    {
        int pos = 0;
        int posfound = 0;
        foreach (var item in arr)
        {
            pos = pos + 1;
            if (item == var1)
            {
                posfound = pos;
                if (posfound >= 1)
                    break;
            }     
        }  
        return posfound;
    }
}
}

GetCommandLine must be a static function


string btchid = classnamehere.GetCommandLine(); Assuming that GetCommandLine is static


Something like this:

[STAThread]
static void Main(string[] args) {
    string btchid = GetCommandLine();// GetCommandline is a mthod which returns a string 
}

static string GetCommandLine(){
    return "Some command line";
}

Need Your Help

where are the .pyc files?

python bytecode

I am a complete newb to python, hence a silly question.