添加“c"有什么作用?在 VB.NET 字符数组中做什么? [英] What does adding a "c" do in a VB.NET character array?

查看:35
本文介绍了添加“c"有什么作用?在 VB.NET 字符数组中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 String 方法 IndexOfAny 来检查指定字符串中是否存在字符.

I would like to use the String method IndexOfAny to check if a character exists in a specified string.

我在网上找到的使用 IndexOfAny 方法的示例在使用 VB.NET 时在字符数组中的每个字符后包含一个c".但是,当我查看 VB.NET 中简单字符数组的示例时,我没有在每个字符后看到任何这样的c".c"有什么作用?是可选的吗?

Examples I've found online, of using the IndexOfAny method include a "c" after each character in the character array when using VB.NET. However, when I look at examples of simple character arrays in VB.NET, I dont see any such "c" after each character. What does the "c" do? Is it optional?

Dim s1 As String = "Darth is not my father."
' Find the first index of either "x" or "n"
Dim i1 As Integer = s1.IndexOfAny(New Char() {"x"c, "n"c})

推荐答案

这是 System.Char 类型文字的后缀.所以

That is a suffix for a literal of type System.Char. So

Dim foo As Char = "x"c

将编译(当 Option Strict 设置为 On 或 Off 时).如果没有 c,它将被解释为字符串.有关 VB.NET 中文字后缀的更多信息,请查看 MSDN 页面,常量和文字数据类型".

Will compile (when Option Strict is set to either On or Off). Without the c, it would be interpreted as a string. For more information about literal suffixes in VB.NET, take a look at the MSDN page, "Constant and Literal Data Types".

这篇关于添加“c"有什么作用?在 VB.NET 字符数组中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆