c#-to-vb.net

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# enumerable class - compatible with VBA

流过昼夜 提交于 2019-11-30 20:19:38
Can anyone instruct me on how to code a C# enumerable class such that the "for each" construct in Excel VBA works properly? I tried this out with a test class called People that implements IEnumerable and contains an array of Person objects. The "foreach" construct works fine in C#, but in VBA I am only able to loop the old fashioned way. This VBA code works just fine: Dim P As Person Dim PP As New People For i = 0 To PP.Count - 1 Set P = PP(i) Debug.Print P.firstName + " " + P.lastName Next i But this fails at run time ("Object doesn't support this property or method"): For Each P In PP Debug

VB.NET Equivalent of this code

女生的网名这么多〃 提交于 2019-11-30 12:08:14
What would be the VB.NET equivalent of this code.. public virtual ICollection<Comment> Comments { get; set; } VB.NET (in version 10) has automatic properties just like C#. The equivalent syntax is as follows: Public Overridable Property Comments() As ICollection(Of Comment) The automatic converters tend to produce syntax that is more verbose than necessary. You can expand it if you want, but it's not strictly necessary unless you're using an older version of the compiler: Private m_Comments As ICollection(Of Comment) Public Overridable Property Comments() As ICollection(Of Comment) Get Return

How to read an integer using console.readline()?

只谈情不闲聊 提交于 2019-11-30 10:10:11
问题 I'm a beginner who is learning .NET. I tried parsing my integer in console readline but it shows a format exception. My code: using System; namespace inputoutput { class Program { static void Main() { string firstname; string lastname; // int age = int.Parse(Console.ReadLine()); int age = Convert.ToInt32(Console.ReadLine()); firstname = Console.ReadLine(); lastname=Console.ReadLine(); Console.WriteLine("hello your firstname is {0} Your lastname is {1} Age: {2}", firstname, lastname, age); } }

c# enumerable class - compatible with VBA

你离开我真会死。 提交于 2019-11-30 04:09:06
问题 Can anyone instruct me on how to code a C# enumerable class such that the "for each" construct in Excel VBA works properly? I tried this out with a test class called People that implements IEnumerable and contains an array of Person objects. The "foreach" construct works fine in C#, but in VBA I am only able to loop the old fashioned way. This VBA code works just fine: Dim P As Person Dim PP As New People For i = 0 To PP.Count - 1 Set P = PP(i) Debug.Print P.firstName + " " + P.lastName Next

How to read an integer using console.readline()?

 ̄綄美尐妖づ 提交于 2019-11-29 18:26:59
I'm a beginner who is learning .NET. I tried parsing my integer in console readline but it shows a format exception. My code: using System; namespace inputoutput { class Program { static void Main() { string firstname; string lastname; // int age = int.Parse(Console.ReadLine()); int age = Convert.ToInt32(Console.ReadLine()); firstname = Console.ReadLine(); lastname=Console.ReadLine(); Console.WriteLine("hello your firstname is {0} Your lastname is {1} Age: {2}", firstname, lastname, age); } } } If it's throwing a format exception then that means the input isn't able to be parsed as an int .

VB.NET Equivalent of this code

泄露秘密 提交于 2019-11-29 17:12:46
问题 What would be the VB.NET equivalent of this code.. public virtual ICollection<Comment> Comments { get; set; } 回答1: VB.NET (in version 10) has automatic properties just like C#. The equivalent syntax is as follows: Public Overridable Property Comments() As ICollection(Of Comment) The automatic converters tend to produce syntax that is more verbose than necessary. You can expand it if you want, but it's not strictly necessary unless you're using an older version of the compiler: Private m

What is the VB.NET equivalent of the C# “is” keyword?

筅森魡賤 提交于 2019-11-29 02:48:32
I need to check if a given object implements an interface. In C# I would simply say: if (x is IFoo) { } Is using a TryCast() and then checking for Nothing the best way? Try the following if TypeOf x Is IFoo Then ... Like this: If TypeOf x Is IFoo Then The direct translation is: If TypeOf x Is IFoo Then ... End If But (to answer your second question) if the original code was better written as var y = x as IFoo; if (y != null) { ... something referencing y rather than (IFoo)x ... } Then, yes, Dim y = TryCast(x, IFoo) If y IsNot Nothing Then ... something referencing y rather than CType or

Differences in LINQ syntax between VB.Net and C#

南笙酒味 提交于 2019-11-28 21:28:48
Again , just out of curiosity: After I have programmed several projects in VB.Net I to my surprise discovered that there are some more than subtle differences between C# and VB.NET LINQ usage. For example, if we want to group elements by multiple properties (columns) we need to create a new anonymous type explicitly: var procs = from c in Process.GetProcesses() group c by new {c.BasePriority, c.Id} into d select d; whereas in VB.NET more straightforward syntax will already do: Dim b = From c In Process.GetProcesses() Group c By c.BasePriority, c.Id Into Group Select Group So, one does not need