单引号 [英] quotedstr
问题描述
亲爱的
我必须将一些代码从Delphi转换为C#.
由于在C#中,函数quotedstr不可用,所以我为此创建了自己的方法(可以在其他地方找到此代码)
I have to convert some code from Delphi to C#.
Since in C#the function quotedstr is not available I made my own methode for it (ok found this code somewhere else)
[代码]
[code]
公共字符串带引号的str(字符串文本)
{
字符串结尾='''';;
返回结尾+文字+结尾;
}
public string quotedstr(string text)
{
string ends = "'";
return ends + text + ends;
}
[/code]
我在Global类(与程序的其余部分位于相同的名称空间)中调用了此代码.
但是当我尝试称呼这个
[代码]
OD_Glob.quotedstr("test"));
[/code]
I invoked this code in my Global class (which is in the same namespace as th rest of my program)
but when I try to call this
[code]
OD_Glob.quotedstr("test");
[/code]
我收到以下错误
错误 CS0120 非静态字段,方法或属性'OD_Glob.quotedstr(string)'
Error CS0120 An object reference is required for the non-static field, method, or property 'OD_Glob.quotedstr(string)'
这有什么问题?
推荐答案
quotedstr被定义为实例函数.因此,当然,您需要一个实例来使用它.
quotedstr is defined as an instance function. So of course you need an instance to use it.
您要么必须创建一个包含该函数的wichever类的实例(您没有显示该实例),要么必须将该函数转换为静态函数.后者似乎更合适.
You either have to create an instance of wichever class contains that function (you did not show that), or have to turn the function into a static one. The later seems more fitting.
这篇关于单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!