vb.net中有这样的相同功能的语法吗?

sutter 2006-07-20 12:16:29

ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = "test.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);

ConfigSectionData data = config.SectionGroups["group1"].Sections["add"] as ConfigSectionData;


说明 ConfigSectionData 是一个自定义类,特别是最后一句:ConfigSectionData data = config.SectionGroups["group1"].Sections["add"] as ConfigSectionData; 这个等号后面还可以 as ,这是什么意思啊,vb.net中有这样的相同功能的语法吗?
...全文
186 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
copall 2006-07-20
  • 打赏
  • 举报
回复
发现3个钻石...
saucer 2006-07-20
  • 打赏
  • 举报
回复
if config.SectionGroups("group1").Sections("add") is nothing then
'such group/section doesn't exist
elseif TypeOf config.SectionGroups("group1").Sections("add") Is ConfigSectionData then
'....
end if
sutter 2006-07-20
  • 打赏
  • 举报
回复
怎么调试时 提示 config.SectionGroups("group1").Sections("add") 未将对象引用到实例
saucer 2006-07-20
  • 打赏
  • 举报
回复
no, in VB.NET, you have to use CType or DirectCast

the safest approach is to check the type first

if TypeOf config.SectionGroups("group1").Sections("add") Is ConfigSectionData then
'....
end if

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧