开发者

One method not seeing another method in the same namespace

开发者 https://www.devze.com 2023-04-03 10:37 出处:网络
Why do these errors occur, and how can they be fixed? Error1Expected class, delegate, enum, interface, or structC:\\Documents and Settings\\agordon\\My Documents\\Visual Studio 2008\\Projects\\lomdb\

Why do these errors occur, and how can they be fixed?

Error 1 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\DAL.cs 9 19 EnterData

Error 2 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\DAL.cs 11 54 EnterData

Error 3 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\DAL.cs 25 23 EnterData

Error 4 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\DAL.cs 27 57 EnterData

Error 5 Type or namespace definition, or end-of-file expected C:\Documents and Settings\agordon\My Documents\Visual Studio 208\Projects\lomdb\EnterData\DataEntry\DAL.cs 39 9 EnterData

Error 8 The name 'PopulateMainForm' does not exist in the current context C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\WebForm1.aspx.cs 25 53 EnterData

Error 9 The name 'PopulateBatchTable' does not exist in the current context C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\WebForm1.aspx.cs 26 50 EnterData

Error 10 The name 'PopulateProblemTable' does not exist in the current context C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\WebForm1.aspx.cs 27 54 EnterData

Error 11 The name 'PopulateSpecimenTable' does not exist in the current context C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\WebForm1.aspx.cs 28 56 EnterData

I am keeping the IList classes in a file called DAL.cs in the same directory:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RadarGraphInsertDLL;

namespace EnterData.DataEntry
{
    public static IList<LOMDLL.Lom_Batch> PopulateBatchTable()
        {
            IList<LOMDLL.Lom_Batch> BatchTable = new IList<LOMDLL.Lom_Batch>();

            try 
            {
            
            }
            catch (Exception e)
            {

            }

            return BatchTable;
        }

        public static IList<LOMDLL.Lom_Problem> PopulateProblemTable()
        {
            IList<LOMDLL.Lom_Problem ProblemTable = new IList<LOMDLL.Lom_Problem();

            try
            {

            }
            catch (Exception e)
            {

            }

            return ProblemTable;
        }

        public static IList<LOMDLL.Lom_Specimen> PopulateSpecimenTable()
        {
            IList<LOMDLL.Lom_Specimen SpecimenTable = new IList<LOMDLL.Lom_Specimen();

            try
            {

            }
            catch (Exception e)
            {

            }

            return SpecimenTable;
        }

        public static LOMDLL.Main_Lom_Form PopulateMainForm()
        {
            //populate class
            LOMDLL.Main_Lom_Form TheForm = new LOMDLL.Main_Lom_Form();

            try
            {
                TheForm.lom_number = lom_numberTextBox.Text.ToInt();
                TheForm.identified_by = ide开发者_高级运维ntified_byTextBox.Text;
                TheForm.occurrence_date = occurrence_dateTextBox.Text.ToDateTime();
                //TheForm.pre_contact = pre_contactTextBox.Text; //need to create this texdtbox
                //TheForm.pre_practice_code = pre_practice_codeTextBox.Text; //create this
                TheForm.report_by = report_byTextBox.Text;
                TheForm.report_date = report_dateTextBox.Text.ToDateTime();
                TheForm.section_c_comments = section_c_commentsTextBox.Text;
                TheForm.section_c_issue_error_identified_by = section_c_issue_error_identified_byTextBox.Text;
                TheForm.section_d_investigation = section_d_investigationTextBox.Text;
                TheForm.section_e_corrective_action = section_e_corrective_actionTextBox.Text;
                TheForm.section_f_comments = section_f_commentsTextBox.Text;
            }
            catch(Exception e)
            {
                
            }

            return TheForm;
        }
}


Your code isn't valid. You cannot declare methods at namespace scope, they must reside in a class (or some other type) definition.

namespace EnterData.DataEntry
{
    public class Foo
    {
        public static IList<LOMDLL.Lom_Batch> PopulateBatchTable()
        {
            // code here...
        }
    }
}


DAL.cs has a namespace that directly contains a method declaration. Namespaces may not contain method declarations. Namespaces are allowed to contain classes, delegates, enums, interfaces, structs, or other namespaces. Hence the error message that a class, delegate, enum, interface or struct was expected.

What you want is a static class:

namespace DataEntry
{
     static class MyClass
     {
         public static IList<LOMDLL.Lom_Batch> PopulateBatchTable() 
         { ... }
     }
}

and then you call MyClass.PopulateBatchTable().


In DAL.cs you are missing a class declaration:

namespace EnterData.DataEntry
{
   public static class DAL // Add Class Here
   {
      public static IList<LOMDLL.Lom_Batch> PopulateBatchTable()
      {

Then in your webform, youll need to use the class name to call the static functions

...
protected void SubmitData(object sender, EventArgs e)
{
   LOMDLL.Main_Lom_Form MainLomFormTable = DAL.PopulateMainForm(); // Add DAL.


One cannot declare functions outside a class definition. What you have done is declare a set of functions without a class definition.

Usually this works with Visual Basic in the form of a module ( in non-.net world).

Since, I cannot comment on the first answer there I am just posting a new answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消