Hi,
in order to organise the functions based on its usage, i want to add a new code file to the project.
I tried to add a new code file and gave a name to it and then wrote a function in it . This function is called from another file . I am getting a lot of error like

Error	1	Expected class, delegate, enum, interface, or struct

To add a new File for classes you choose
1- add new item
2- choose class file
but if you want to # separate the methods or property from the same class to another file you have add the partial keyword for booth files like this

public partial  class myclass
{
   // code part A
}
// in another file add
public partial  class myclass
{
   // code part B
}
Comments
Nice answer

First, make sure the files are in the same namespace. Look at the top few lines of each after the using statements to see. If that's not the problem type out the steps you followed to add the file in.

EDIT: What mahmoud says may be the way to go if they are in the same class. If it's a new class you're starting do the namespace check.

Edited 6 Years Ago by jonsca: n/a

To add a new File for classes you choose
1- add new item
2- choose class file
but if you want to # separate the methods or property from the same class to another file you have add the partial keyword for booth files like this

public partial  class myclass
{
   // code part A
}
// in another file add
public partial  class myclass
{
   // code part B
}

Thanks this helped, Hope this can be used to add any number of files like this

First, make sure the files are in the same namespace. Look at the top few lines of each after the using statements to see. If that's not the problem type out the steps you followed to add the file in.

EDIT: What mahmoud says may be the way to go if they are in the same class. If it's a new class you're starting do the namespace check.

I want it to be in same class

when you add a new code file the VS give you a blank document so you may forget to add the namespace but you can follow the Previous steps as you want it to be in the same class
but it's good thing to check the namespace and classes name.

Edited 6 Years Ago by mahmoud_wow: n/a

This question has already been answered. Start a new discussion instead.