找不到将VB.Net转换为C#类型或命名空间

找不到将VB.Net转换为C#类型或命名空间,c#,C#,我正在将一个VB.Net项目转换为C#。我在一个模块中声明一些公共结构,并在另一个模块中访问它们。我得到一个“找不到类型或命名空间名称'ItemInfo'。-其中ItemInfo是结构之一。下面是我声明结构的代码片段: using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawi

我正在将一个VB.Net项目转换为C#。我在一个模块中声明一些公共结构,并在另一个模块中访问它们。我得到一个“找不到类型或命名空间名称'ItemInfo'。-其中ItemInfo是结构之一。下面是我声明结构的代码片段:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Data.Common;
using System.IO;
using System.Net.Mail;
using dbAutoTrack.DataReports;
using dbAutoTrack.DataReports.PDFExport;

namespace PlanSchedule
{

    static class PlanScheduleBLL
    {

        #region "Structures"

        public struct ItemInfo
        {
            // LinearProcessTime = sum of bll level resource requirements; 
            // when more than one resource on a level, uses max time required;
            // not saved in database, used in order processing only
            public string ItemNumber;
            public string Description;
            public string MakeBuy;
            public long TotalShelfLife;
            public long ReceivedShelfLife;
            public float YieldPercentage;
            public float BatchSize;
            public float SafetyStock;
        }
…这就是我引用它的地方:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

namespace PlanSchedule
{
public partial class BuildToStockOrderEntry
{


    // slItemList
    // Key = <item number> - <item description> Value = item number
    private SortedList<string, string> slItemList = new SortedList<string, string>();
    // slItems
    // Key = item number Value = item info
    private SortedList<string, ItemInfo> slItems = new SortedList<string, ItemInfo>();
使用Microsoft.VisualBasic;
使用制度;
使用系统集合;
使用System.Collections.Generic;
使用系统数据;
使用系统图;
使用系统诊断;
使用System.Windows.Forms;
名称空间计划表
{
公共部分类BuildToStockOrderEntry
{
//slItemList
//键=-值=项目编号
private SortedList slItemList=新建SortedList();
//slItems
//键=项目编号值=项目信息
私有分类列表slItems=新分类列表();
我不懂C#,所以我的语法可能有问题。我使用ItemInfo声明SortedList是否正确

蒂亚,
John

这是因为您正在另一个类中声明结构。您可以通过执行以下操作来引用它:

private SortedList<string, PlanScheduleBLL.ItemInfo> slItems ...
private SortedList slItems。。。

但是更好的方法是在类之外直接在名称空间本身中定义结构(即去掉PlanScheduleBLL静态类)。

这是因为您在另一个类中声明结构。您可以通过以下操作引用它:

private SortedList<string, PlanScheduleBLL.ItemInfo> slItems ...
private SortedList slItems。。。

但是更好的方法是在类之外直接在名称空间本身中定义结构(即,去掉PlanScheduleBLL静态类)。

您当前在
静态类PlanScheduleBLL
中嵌套了
ItemInfo
结构。您有两个选项:

  • 将它从该类中拉出来,然后直接拉到名称空间中
  • 如果您确实希望嵌套它,则需要将
    PlanScheduleBLL
    公开,并像
    PlanScheduleBLL.ItemInfo

您当前在
静态类PlanScheduleBLL
中嵌套了
ItemInfo
结构。您有两个选项:

  • 将它从该类中拉出来,然后直接拉到名称空间中
  • 如果您确实希望嵌套它,则需要将
    PlanScheduleBLL
    公开,并像
    PlanScheduleBLL.ItemInfo

ItemInfo
结构放在
PlanScheduleBLL
类之外。

ItemInfo
结构放在
PlanScheduleBLL
类之外。

谢谢Jonathon、Dylan和AVD!我将结构移到了类之外,效果很好。这似乎是VB.Net和C#之间的区别。我在类中有它们,但似乎公共声明允许VB.Net从其他模块访问它们。谢谢Jonathon、Dylan和AVD!我将结构移到了类外,效果很好。这似乎是VB.Net和C#之间的区别。我在类中有它们,但似乎公共声明允许VB.Net访问它们来自其他模块。很高兴我们能够提供帮助。如果答案解决了您的问题,请记住接受答案。很高兴我们能够提供帮助。如果答案解决了您的问题,请记住接受答案。