// 假设这个是一个静态类.一切成员都是静态的
public static class a {
public static string strings = null; public static void SetString(string _s) {
strings = _s;
} public static string GetString() {
// 如果 strings 为 null
return strings;
}
}class b {
string strTest = "如果这句话没有被覆盖.请保留.";
b() {
strTest = a.GetString();
}
}
如果 strTest 获取不到值.请不要覆盖.问题是想在 类b 判断 GetString() 的返回值是否为空,在为他处理.
解决方案 »
- C#记事本
- WinForm 你为什么这么闪?
- 用X关闭一个窗口,弹出提示:确定关闭,取消不关闭。各位大虾,怎么实现?
- 主键为字符时GridView更新数据时:能找到带参数的非泛型方法
- 当点击treeView的一个节点时,怎么实现弹出另一个新的窗体?在线等!
- 请问那些在网上下载.net2003并且安装成功的高手们,你们是怎么安装的啊????
- CrystalDecisions.Shared 错误
- extjs中如何获取到数据库中的数据后显示在相应的textfield中
- C# winform TextBox显示带下划线的数字为UU
- telnet服务的内码是如何转换的?
- 如何用C#实现向Sql数据库添加一条记录,就在DataGridView中显示该条记录!!
- 一段代码没看懂
// 假设这个是一个静态类.一切成员都是静态的
public static class a
{
private static string strings = null;
public static string String
{
get
{
return strings;
}
set
{
strings = value;
}
}
}class b
{
string strTest = "如果这句话没有被覆盖.请保留.";
public b()
{
if (a.String != null)
{
strTest = a.String;
}
}
}
public static class A
{
private static string _strs = string.Empty; public static string StrsValue
{
get { return _strs; }
set { _strs = value; }
}
}public class B
{
string test = "我的默认值,A没有给我值";
public B()
{
test = string.IsNullOrEmpty(A.StrsValue) ? test : A.StrsValue;
} public string Write()
{
Console.Write(test);
}
}public class Test
{
public static void Main()
{
B b = new B();
b.Write(); A.StrsValue = "我是A";
B c = new B();
c.Write();
}
}
public static class a {
public static string strings = null; public static void SetString(string _s) {
strings = _s;
} public static string GetString() {
// 如果 strings 为 null
return strings;
}
}class b {
string strTest = "如果这句话没有被覆盖.请保留.";
b() {
strTest = a.GetString();
}
}