Click here to Skip to main content
15,926,035 members
Home / Discussions / C#
   

C#

 
GeneralRe: motherboard Pin
leppie8-Aug-06 22:41
leppie8-Aug-06 22:41 
QuestionISO 8583 Pin
Tiger4568-Aug-06 14:53
Tiger4568-Aug-06 14:53 
QuestionDatagrid doesn't show data [modified] Pin
ircnoob8-Aug-06 14:25
ircnoob8-Aug-06 14:25 
AnswerRe: Datagrid doesn't show data Pin
gkl08188-Aug-06 15:17
gkl08188-Aug-06 15:17 
GeneralRe: Datagrid doesn't show data Pin
ircnoob8-Aug-06 15:28
ircnoob8-Aug-06 15:28 
AnswerRe: Datagrid doesn't show data Pin
ircnoob8-Aug-06 23:14
ircnoob8-Aug-06 23:14 
Questionusing separate codefiles Pin
Glen Harvy8-Aug-06 14:22
Glen Harvy8-Aug-06 14:22 
AnswerRe: using separate codefiles Pin
Leslie Sanford8-Aug-06 16:26
Leslie Sanford8-Aug-06 16:26 
Hmm, when you say you can't use a method in the main code file that is located in another codefile, do you mean that you can't use the class that contains the method in one file in another file?

Let's say you have a file in your project called Program.cs. I'm assuming that we're creating a console application program. Here is what the Program.cs file looks like:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}


Now, let's add a second file, actually we'll be adding a second class that will be contained in a second file. We'll call it MyClass.

Go to Project->Add New Item

Choose Class, and type MyClass in the edit box. Then press the Add button.

Visual studio has created a second file for use called MyClass.cs. It looks like this:

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

namespace ConsoleApplication1
{
    class MyClass
    {
    }
}


Let's add a static method to MyClass that we can call from the Main method in the Program class:

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

namespace ConsoleApplication1
{
    class MyClass
    {
        public static void PrintHello()
        {
            Console.WriteLine("Hello!");
        }
    }
}


Change the Main method in the Program class located in the Program.cs file to look like this:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            MyClass.PrintHello();

            Console.Read();
        }
    }
}


Run the program.

To review: We've created a console application and added a second class called MyClass contained in a second file called MyClass.cs. We called a static method in MyClass from the Main method in the Program class.

Does this example help?

If you need more information, let me know.
GeneralRe: using separate codefiles Pin
Glen Harvy8-Aug-06 18:39
Glen Harvy8-Aug-06 18:39 
GeneralRe: using separate codefiles Pin
Leslie Sanford8-Aug-06 19:05
Leslie Sanford8-Aug-06 19:05 
GeneralRe: using separate codefiles Pin
Glen Harvy8-Aug-06 21:21
Glen Harvy8-Aug-06 21:21 
AnswerRe: using separate codefiles Pin
Nader Elshehabi8-Aug-06 18:45
Nader Elshehabi8-Aug-06 18:45 
QuestionerrorProvider problem [modified] Pin
dustin108-Aug-06 13:25
dustin108-Aug-06 13:25 
AnswerRe: errorProvider problem Pin
stancrm8-Aug-06 22:14
stancrm8-Aug-06 22:14 
QuestionColor deviation algorithm... Pin
Shy Agam8-Aug-06 12:54
Shy Agam8-Aug-06 12:54 
QuestionExplorer bar type applications Pin
martin_hughes8-Aug-06 12:17
martin_hughes8-Aug-06 12:17 
QuestionCustom type casting Pin
Master Toothless One8-Aug-06 11:04
Master Toothless One8-Aug-06 11:04 
AnswerRe: Custom type casting Pin
led mike8-Aug-06 11:08
led mike8-Aug-06 11:08 
AnswerRe: Custom type casting [modified] Pin
Patricker8-Aug-06 12:00
Patricker8-Aug-06 12:00 
GeneralRe: Custom type casting Pin
Master Toothless One8-Aug-06 13:06
Master Toothless One8-Aug-06 13:06 
GeneralRe: Custom type casting Pin
Patricker8-Aug-06 13:44
Patricker8-Aug-06 13:44 
GeneralRe: Custom type casting [modified] Pin
Master Toothless One8-Aug-06 14:05
Master Toothless One8-Aug-06 14:05 
QuestionDatagrid column headers Pin
Naji.A8-Aug-06 9:51
Naji.A8-Aug-06 9:51 
AnswerRe: Datagrid column headers Pin
_AK_8-Aug-06 18:33
_AK_8-Aug-06 18:33 
GeneralRe: Datagrid column headers Pin
Naji.A9-Aug-06 16:26
Naji.A9-Aug-06 16:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.