vb.net-to-c#

Why can't Interface ReadOnly properties be overridden in VB.NET, when it is valid in C#.NET?

空扰寡人 提交于 2019-12-01 16:11:41
(this is related to this other question ) If you define an Interface where there is a Property with only a getter (= ReadOnly in VB.NET), why can you define the setter in implementing classes with C# but not with VB ? I would have thought it was defined at .NET level, and not language-specific. Example: for this interface 'VB.NET Interface SomeInterface 'the interface only say that implementers must provide a value for reading ReadOnly Property PublicProperty As String End Interface or //C# code interface IPublicProperty { string PublicProperty { get; } } This is a correct implementation in C#

Why can't Interface ReadOnly properties be overridden in VB.NET, when it is valid in C#.NET?

孤街醉人 提交于 2019-12-01 15:00:28
问题 (this is related to this other question) If you define an Interface where there is a Property with only a getter (= ReadOnly in VB.NET), why can you define the setter in implementing classes with C# but not with VB ? I would have thought it was defined at .NET level, and not language-specific. Example: for this interface 'VB.NET Interface SomeInterface 'the interface only say that implementers must provide a value for reading ReadOnly Property PublicProperty As String End Interface or //C#

C# equivalent to VB.NET's Catch…When

烈酒焚心 提交于 2019-11-30 17:31:39
In VB.NET I often Catch…When : Try … Catch e As ArgumentNullException When e.ParamName.ToUpper() = "SAMPLES" … End Try Is there a C# equivalent to Catch…When ? I don't want to resort to using an if statement inside a catch if possible. This functionality was announced for C# 6. It is now possible to write try { … } catch (MyException e) when (myfilter(e)) { … } You can download the preview of Visual Studio 2015 now to check this out, or wait for the official release. cruizer There's no equivalent to Catch…When in C#. You will really have to resort to an if statement inside your catch , then

VB.NET Select…Case Statement Equivalent in C#

核能气质少年 提交于 2019-11-30 00:42:41
问题 I just started using C# and I've got a couple of issues. Is there any way to code the C# equivalent of the VB.NET Select statement like the following? Select Object.Name.ToString() Case "Name1" 'Do something Case "Name2" 'Do something else Case Else 'Do the default action End Select Any help would be greatly appreciated. Thanks for the input so far now what about if I hook several controls to one event handler as in the following and I want to perform a slightly different action for each

What is the C# equivalent of CType in VB.NET?

一曲冷凌霜 提交于 2019-11-29 13:49:53
I am trying to convert the example provided in MSDN article Creating Dynamic Data Entry User Interfaces to C#, but am stuck at the following code: CType(dq, IUIBuildingBlock).QuestionText = reader("QuestionText") How do I convert the above VB.NET statement to C#? In C#, you can specify a cast by putting the type you want to cast to in parenthesis in front of the reference variable that you want to cast ( (type)instance ). So, to cast the object ( dq ) to the type IUIBuildingBlock , you could use the following code: ((IUIBuildingBlock)dq).QuestionText = reader("QuestionText"); (Note that this

VB.NET WithEvents keyword behavior - VB.NET compiler restriction?

假如想象 提交于 2019-11-28 21:26:08
I'm working on becoming as familiar with C# as I am with VB.NET (the language used at my workplace). One of the best things about the learning process is that by learning about the other language you tend to learn more about your primary language--little questions like this pop up: According to the sources I've found, and past experience, a field in VB.NET that is declared as WithEvents is capable of raising events. I understand that C# doesn't have a direct equivalent--but my question is: fields without this keyword in VB.NET cannot raise events, is there a way to create this same behavior in

What is the C# equivalent of CType in VB.NET?

做~自己de王妃 提交于 2019-11-28 07:37:35
问题 I am trying to convert the example provided in MSDN article Creating Dynamic Data Entry User Interfaces to C#, but am stuck at the following code: CType(dq, IUIBuildingBlock).QuestionText = reader("QuestionText") How do I convert the above VB.NET statement to C#? 回答1: In C#, you can specify a cast by putting the type you want to cast to in parenthesis in front of the reference variable that you want to cast ( (type)instance ). So, to cast the object ( dq ) to the type IUIBuildingBlock , you

VB to C# Functions

戏子无情 提交于 2019-11-27 17:10:30
Which are the equivalent of the following operators from VB.Net to C#? UBound() LBound() IsNothing() Chr() Len() UCase() LCase() Left() Right() RTrim() LTrim() Trim() Mid() Replace() Split() Join() MsgBox() IIF() Gavin Miller VB C# UBound() = yourArray.GetUpperBound(0) or yourArray.Length for one-dimesional arrays LBound() = yourArray.GetLowerBound(0) IsNothing() = Object.ReferenceEquals(obj,null) Chr() = Convert.ToChar() Len() = "string".Length UCase() = "string".ToUpper() LCase() = "string".ToLower() Left() = "string".Substring(0, length) Right() = "string".Substring("string".Length -

VB.NET WithEvents keyword behavior - VB.NET compiler restriction?

不打扰是莪最后的温柔 提交于 2019-11-27 13:50:29
问题 I'm working on becoming as familiar with C# as I am with VB.NET (the language used at my workplace). One of the best things about the learning process is that by learning about the other language you tend to learn more about your primary language--little questions like this pop up: According to the sources I've found, and past experience, a field in VB.NET that is declared as WithEvents is capable of raising events. I understand that C# doesn't have a direct equivalent--but my question is:

VB to C# Functions

淺唱寂寞╮ 提交于 2019-11-26 18:55:56
问题 Which are the equivalent of the following operators from VB.Net to C#? UBound() LBound() IsNothing() Chr() Len() UCase() LCase() Left() Right() RTrim() LTrim() Trim() Mid() Replace() Split() Join() MsgBox() IIF() 回答1: VB C# UBound() = yourArray.GetUpperBound(0) or yourArray.Length for one-dimesional arrays LBound() = yourArray.GetLowerBound(0) IsNothing() = Object.ReferenceEquals(obj,null) Chr() = Convert.ToChar() Len() = "string".Length UCase() = "string".ToUpper() LCase() = "string".ToLower