I am converting a VB.Net project to C#. I declare some public structures in one module and access them in another. I get a "The type or namespace name 'ItemInfo' could not be found." - where ItemInfo is one of the structures. Here is code snippet where I declare the structure:
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;
}
...and this is where I reference it:
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>();
I do not know C# so I may have a problem in my syntax. Is my declaration of the SortedList using ItemInfo correct?
TIA, John
You currently have the ItemInfo
struct nested in the static class PlanScheduleBLL
. You have two options:
PlanScheduleBLL
public, and refer to it like PlanScheduleBLL.ItemInfo
It's because you are declaring the struct inside another class. You could reference it by doing:
private SortedList<string, PlanScheduleBLL.ItemInfo> slItems ...
But a much better approach would be to just define the struct outside of the class and directly in the namespace itself (ie get rid of the PlanScheduleBLL static class).
将ItemInfo
结构放置在PlanScheduleBLL
类之外。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.