VB.NET中自定义访问说明符与C#的访问修饰符有何相似之处?

2026-05-06 11:331阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计362个文字,预计阅读时间需要2分钟。

VB.NET中自定义访问说明符与C#的访问修饰符有何相似之处?

在VB.Net中,并没有直接对应于这种操作的函数或属性。通常,您需要通过编程方式来实现类似的功能。例如,如果您想要比较两个字符串是否相对相同,您可能需要编写一个自定义函数来逐字符比较它们的相似度。以下是一个简化的例子:

vbFunction IsRelativelySame(str1 As String, str2 As String) As Boolean If str1.Length str2.Length Then Return False End If

VB.NET中自定义访问说明符与C#的访问修饰符有何相似之处?

For i As Integer=0 To str1.Length - 1 If str1(i) str2(i) Then Return False End If Next

Return TrueEnd Function

使用这个函数,您可以比较两个字符串是否完全相同。如果您想要一个更复杂的比较,比如忽略大小写或某些特定字符,您可能需要进一步扩展这个函数。

我只是想知道在VB.Net中是否有一个相当于这种C#的简写,包括私有的setter:

public string Test { get; private set; }

有人可以告诉我在VB.Net中实现这一目标的最短路径吗?

对不起,这是VB.NET中的 not possible:

Auto-implemented properties are
convenient and support many
programming scenarios. However, there
are situations in which you cannot use
an auto-implemented property and must
instead use standard, or expanded,
property syntax.

You have to use expanded
property-definition syntax if you want
to do any one of the following:

  • Create properties that are WriteOnly or ReadOnly.

本文共计362个文字,预计阅读时间需要2分钟。

VB.NET中自定义访问说明符与C#的访问修饰符有何相似之处?

在VB.Net中,并没有直接对应于这种操作的函数或属性。通常,您需要通过编程方式来实现类似的功能。例如,如果您想要比较两个字符串是否相对相同,您可能需要编写一个自定义函数来逐字符比较它们的相似度。以下是一个简化的例子:

vbFunction IsRelativelySame(str1 As String, str2 As String) As Boolean If str1.Length str2.Length Then Return False End If

VB.NET中自定义访问说明符与C#的访问修饰符有何相似之处?

For i As Integer=0 To str1.Length - 1 If str1(i) str2(i) Then Return False End If Next

Return TrueEnd Function

使用这个函数,您可以比较两个字符串是否完全相同。如果您想要一个更复杂的比较,比如忽略大小写或某些特定字符,您可能需要进一步扩展这个函数。

我只是想知道在VB.Net中是否有一个相当于这种C#的简写,包括私有的setter:

public string Test { get; private set; }

有人可以告诉我在VB.Net中实现这一目标的最短路径吗?

对不起,这是VB.NET中的 not possible:

Auto-implemented properties are
convenient and support many
programming scenarios. However, there
are situations in which you cannot use
an auto-implemented property and must
instead use standard, or expanded,
property syntax.

You have to use expanded
property-definition syntax if you want
to do any one of the following:

  • Create properties that are WriteOnly or ReadOnly.