一个解决方案中,有两个项目,A项目有一个类,如何在B项目中用呢?
---------------------------------------
A项目的命名空间是 d8020,B空间的命名空间是d8020_2
我在A项目建了一个类,我想在B项目用它,可以我在B空间却不知如何用,
为何using d8020;还不行呢?
我在B项目中已经添加一个 d8020的引用了呀。
错误 1 找不到类型或命名空间名称“d8020”(是否缺少 using 指令或程序集引用?) D:\c#temp\d0820\d0820_2\Form1.cs 9 7 d0820_2
B项目代码如下:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using d8020;
namespace d0820_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
}
}
}
A项目代码如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace d0820
{
public class zghcls
{
private int myint = 12; #region properties
public int myprop
{
get
{
return myint;
} set
{
myint = value;
} }
#endregion
} class Program
{
static void Main(string[] args)
{
zghcls obj1=new zghcls();
Console.WriteLine("类名称为:{0}",obj1.ToString());
Console.ReadKey();
}
}
}
---------------------------------------
A项目的命名空间是 d8020,B空间的命名空间是d8020_2
我在A项目建了一个类,我想在B项目用它,可以我在B空间却不知如何用,
为何using d8020;还不行呢?
我在B项目中已经添加一个 d8020的引用了呀。
错误 1 找不到类型或命名空间名称“d8020”(是否缺少 using 指令或程序集引用?) D:\c#temp\d0820\d0820_2\Form1.cs 9 7 d0820_2
B项目代码如下:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using d8020;
namespace d0820_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
}
}
}
A项目代码如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace d0820
{
public class zghcls
{
private int myint = 12; #region properties
public int myprop
{
get
{
return myint;
} set
{
myint = value;
} }
#endregion
} class Program
{
static void Main(string[] args)
{
zghcls obj1=new zghcls();
Console.WriteLine("类名称为:{0}",obj1.ToString());
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using d8020;
namespace d0820_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
zghcls zg=new zghcls();
zg...........
}
}
}
刚试过你的代码,是可以的,winform\Console都可以。
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
CaseService cs = null;
zghcls pg = null;
}
}
}