我想在离开前一个函数,根据返回code和变量的函数来设置一个usererror字符串。
I wish to set a usererror string before leaving a function, depending on the return code and variable in the function.
我目前有:
Dim RetVal as RetType
try
...
if ... then
RetVal = RetType.FailedParse
end try
endif
...
finally
select case RetVal
case ...
UserStr = ...
end select
end try
return RetVal
是否可以使用回RetType.FailedParse,然后访问该在finally块?
Is it possible to use return RetType.FailedParse, then access this in the finally block?
做这在C#是在方法的开始来声明一个变量的唯一真正的方式来保存值 - 即
The only real way of doing this in C# would be to declare a variable at the start of the method to hold the value - i.e.
SomeType result = default(SomeType); // for "definite assignment"
try {
// ...
return result;
}
finally {
// inspect "result"
}
在VB中,你的也许的能够直接访问的结果 - 因为IIRC它有点就像上面(与方法名称中的结果)反正。警告:我的真的不是一个VB的人......
In VB, you might be able to access the result directly - since IIRC it kinda works like the above (with the method name as "result") anyway. Caveat: I'm really not a VB person...