Show/Hide Toolbars

XSharp

 

该实体类型不能返回值。返回值被忽略。

 

遗憾的是,VO 允许从赋值中返回值。由于 .NET 不允许这样做,X# 编译器将返回以下错误

警告 XS9032 该实体类型不能返回值。返回值被忽略。

以下代码在 VO 中完全有效,但在 X# 中却会抛出此警告:

class MyClass
 protect _cMyVar as string
 

access MyVar

 return _cMyVar

 
assign MyVar( cMyVar
 _cMyVar := cMyVar
 
 return _cMyVar

 

end class

 

to solve the problem simply remove the return value from the return statement inside the Assign:

class MyClass
 protect _cMyVar as string
 
access MyVar

 return _cMyVar

 
assign MyVar( cMyVar )
 _cMyVar := cMyVar
 return

 

end class

 

 

and if you are changing the code anyway it is also a good idea to add typing to your access/assign:

 

class MyClass
 protect _cMyVar as string

 
access MyVar as string

 return _cMyVar
assign MyVar( cMyVar as string )
 _cMyVar := cMyVar
 return

 

end class