大家好,我现在遇到一个操作符重载的问题,请大家帮忙解决:public class Test
{
public int Value;
}
public class Program
{
static void Main(string[] args)
{
Test t = new Test();
Console.WriteLine(t.Value); // 这样的代码 OK Console.WriteLine(Test.Value); // 这样的代码错误 // 这就是我的问题,我怎么实现一个字段(或者属性),通过使用
// 类.xxx 和 对象.xxx
// 都不报错(但是'.'好像不能够被重载)
}
}// 谢谢大家的帮助
{
public int Value;
}
public class Program
{
static void Main(string[] args)
{
Test t = new Test();
Console.WriteLine(t.Value); // 这样的代码 OK Console.WriteLine(Test.Value); // 这样的代码错误 // 这就是我的问题,我怎么实现一个字段(或者属性),通过使用
// 类.xxx 和 对象.xxx
// 都不报错(但是'.'好像不能够被重载)
}
}// 谢谢大家的帮助
using System;namespace prjCx
{
/// <summary>
/// clsGlobalSingleton 的摘要说明。
/// </summary>
public class clsGlobalSingleton:clsGlobal
{
private static clsGlobal clsglobal=null; // 声明静态类; public clsGlobalSingleton()
{
//
// TODO: 在此处添加构造函数逻辑
//
} /// <summary>
/// 饿汉单太模式 返回类 clsGlobal 的实例
/// </summary>
public static clsGlobal GlobalInstance
{
get
{
if (clsglobal == null)
{
clsglobal =new clsGlobal();
}
return clsglobal;
}
} }
}
{ public static void LogAA()
{
...
}
}就可以用clsAA.LogAA();
// 例如我有一个类,客户
Customer customer = new Customer();
customer.Name = "Test";
customer.Save();
// 这样,我创建一个客户对象,设置他的名字,并保存。
// 然后我接着写一个查询把他查出来
Customer customer2 = new Query<Customer>(Customer.Name.Like("Test")).GetEntity();
if( customer2 != null )
{
Console.WriteLine(customer2.Name);
}
// 屏幕输出: Test
请看查询条件代码:Customer.Name.Like("Test") ,在这里我要使用类.字段(或者属性)
请问,我怎么实现这个 Customer 类,最关键是 类.字段 和 对象.字段 同时指向一个东东
{
public string Name;
public static string Name;
}我就想不通为什么上边的代码微软就是不给编译,一个静态,一个非静态,井水不犯河水,又不会有什么影响,晕
请看查询条件代码:Customer.Name.Like("Test") ,在这里我要使用类.字段(或者属性)
请问,我怎么实现这个 Customer 类,最关键是 类.字段 和 对象.字段 同时指向一个东东
************************************************************************************
类.字段:这样静态的只有一个,
对象.字段:你说类可以创建多少个对象,类.字段要指向哪个对象的字段呢?你说这有可能么?
你既然已经查询出customer2,为何不直接用customer2对象去取Name,要用类.Name。
你其实就是想在保存的前面只赋值,后面直接调用。那样的话,你只能用一个静态的变量!
Customer customer = new Customer();
customer.Name = "Test";
Customer.staticName="Test" //这样你在查询时就可以用这个变量
customer.Save();