2011-11-11 51 views
0

我將一個VB.Net項目轉換爲C#。我在一個模塊中聲明一些公共結構,並在另一個模塊中訪問它們。我收到「無法找到類型或名稱空間名稱」ItemInfo「。」 - 其中ItemInfo是其中一個結構。下面是代碼片段,我宣佈結構:將VB.Net轉換爲C#類型或名稱空間未找到

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>(); 

我不知道C#,所以我可以在我的語法有問題。我使用ItemInfo對SortedList的聲明是否正確?

TIA, 約翰

+0

很高興我們可以提供幫助。如果它解決了你的問題,請記住接受答案。 –

回答

2

這是因爲您聲明另一個類的內部結構。你可以做參考吧:

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

但更好的方法是隻定義類的直接在命名空間本身之外和結構(即擺脫PlanScheduleBLL靜態類的)。

4

您目前有ItemInfo結構嵌套static class PlanScheduleBLL。你有兩種選擇:

  • 把它從這個類中拉出來,放到命名空間中。
  • 如果你真的它嵌套,你需要做PlanScheduleBLL公開,是指它就像PlanScheduleBLL.ItemInfo
0

放置ItemInfo結構PlanScheduleBLL類之外。

+0

謝謝Jonathon,Dylan和AVD!我在課堂以外的地方移動了這些結構,它效果很好。看起來這是VB.Net和C#之間的區別。我在課堂上有他們,但似乎公開聲明允許VB.Net從其他模塊訪問它們。 –

相關問題