COnvert String变量为vb.net中的COnst字符串 [英] COnvert String Variable to COnst string in vb.net
本文介绍了COnvert String变量为vb.net中的COnst字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我需要将一个字符串值传递给const字符串值。我将附加下面的代码。我将字符串变量传递给const字符串需要持续表达错误获取。
Dim s 作为 字符串 = sss
Const ZSTransID As String = s
请帮我解决
问候
Sreejith
解决方案
我担心首先你需要了解Constant在.Net中的含义。在这里阅读文档是MSDN:
http ://msdn.microsoft.com/en-us/library/zb8fth98.aspx [ ^ ]
在上面的示例中,您需要了解对常量的赋值只能是编译时常量。这是你仍然可以做的(它在C#中),但基本上意味着你必须将s声明为常量。
我不确定在实践中是否会对你有帮助。
const string s = < span class =code-string> sss;
const string ZSTransID = s;
顺便说一下,你可能想看一下 ReadOnly [ ^ ]关键字以及比较它与Const。
Const and只读关键字 [ ^
Dear All,
I need to pass a string value to const string value.I will attach the code below.While I pass the string variable to const string "constant expression required " error getting.
Dim s As String = "sss"
Const ZSTransID As String = s
Please help me to solve
Regards
Sreejith
解决方案
I am afraid that first you need to understand what Constant is in .Net. Read the documentation is MSDN here:
http://msdn.microsoft.com/en-us/library/zb8fth98.aspx[^]
In you above example, you need to understand that an assignment to a constant can only be a compile time constant. This is what you could still do (it's in C#), but basically means that you have to declare s as constant as well.
I am not sure if in practice that would help you.
const string s = "sss"; const string ZSTransID = s;
Btw, you might want to look at the ReadOnly [^]keyword as well and compare it with Const.
Const and Readonly Keywords[^]
这篇关于COnvert String变量为vb.net中的COnst字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文