是否有一种安全的方法可以在 Visual Basic 中声明字符串变量? [英] Is there a secure way to declare a string variable in visual basic?
问题描述
在使用 PHP 时,我总是声明我的字符串变量并将它们设置为 null 以确保安全.我是visual basic的新手,想知道声明字符串变量的最安全方法是什么.将
When working with PHP I always declared my string variable and set them equal to null just to be safe. I'm new to visual basic and am wondering what the safest way to declare a string variable is. Will
Dim strWords As String
够了吗?或者将其设置为 null 或没有或其他一些默认值或原始类型更好?
be sufficient? Or is it better to set it to null or nothing or some other default value or primitive type?
推荐答案
默认情况下,strWords 无论如何都会Nothing
.
By default, strWords will be Nothing
by default anyway.
与其在声明变量时通过设置一个值来确保这个值永远不会是空的,你应该确保你的代码不会留下 strWords
为空的可能性,如果是的话,处理适当.
Rather than ensuring this value is never nothing by setting a value when declaring the variable, you should ensure your code doesn't leave the possibility of strWords
being Nothing, and if it is, dealing with it appropriately.
如果你需要检查一个字符串是否为空或不为空,你可以这样做:
If you need to check whether a string is not empty or nothing, you can do:
If Not String.IsNullOrEmpty(strWords) Then
这篇关于是否有一种安全的方法可以在 Visual Basic 中声明字符串变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!