vb.net-to-c#

Why cannot convert null to type parameter T in c#?

霸气de小男生 提交于 2020-01-21 08:03:17
问题 I'm converting a bunch of code from VB to C# and I'm running in to an issue with a method. This VB method works great: Public Function FindItem(ByVal p_propertyName As String, ByVal p_value As Object) As T Dim index As Int32 index = FindIndex(p_propertyName, p_value) If index >= 0 Then Return Me(index) End If Return Nothing End Function It allow the return of Nothing(null) for T. The C# equivalent does not work: public T FindItem(string p_propertyName, object p_value) { Int32 index =

Converting a Youtube downloader form VB to C# [closed]

南楼画角 提交于 2020-01-17 13:46:10
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Im working on a youtube downloader class. And I got vb.net version which I would like to port to C#. But im running in so problems. So any help would be nice. Also the only type i'm going to use is .mp3. Original post on hack forums: http://www.hackforums.net/showthread.php?tid

Converting a Youtube downloader form VB to C# [closed]

余生长醉 提交于 2020-01-17 13:46:08
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Im working on a youtube downloader class. And I got vb.net version which I would like to port to C#. But im running in so problems. So any help would be nice. Also the only type i'm going to use is .mp3. Original post on hack forums: http://www.hackforums.net/showthread.php?tid

Converting inerface with delegate from vb to c#

南楼画角 提交于 2020-01-05 08:09:21
问题 I've got interface: Public Interface ICSIItem Sub Initialize() Event AnswerValueChanged(ByVal sender As Object, ByVal e As NotebookAnswerChangedEventArgs) Property DataContext() As Object End Interface and converter http://www.developerfusion.com/tools/convert/vb-to-csharp/ public interface ICSIItem { void Initialize(); event AnswerValueChangedEventHandler AnswerValueChanged; delegate void AnswerValueChangedEventHandler(object sender, NotebookAnswerChangedEventArgs e); object DataContext {

What is the C# equivalent of ChrW(e.KeyCode)?

蓝咒 提交于 2020-01-03 06:53:07
问题 In VB.NET 2008, I used the following statement: MyKeyChr = ChrW(e.KeyCode) Now I want to convert the above statement into C#. Any Ideas? 回答1: Looks like the C# equivalent would be var MyKeyChr = char.ConvertFromUtf32((int) e.KeyCode) However, e.KeyCode does not contain a Unicode codepoint, so this conversion is meaningless. 回答2: The quick-and-dirty equivalent of ChrW in C# is simply casting the value to char : char MyKeyChr = (char)e.KeyCode; The longer and more expressive version is to use

What is the best alternative “On Error Resume Next” for C#?

﹥>﹥吖頭↗ 提交于 2020-01-01 07:58:07
问题 If I put empty catch blocks for my C# code, is it going to be an equivalent for VB.NET's "On Error Resume Next" statement. try { C# code; } catch(exception) { } The reason I am asking this is because I have to convert a VB.NET code to C#, and the old code has ~200 "On Error Resume Next" statements although I am using a proper try {} catch {} in my new code, but is there is a better alternative? 回答1: I've found that VB programmers often littered code with many On Error Resume Next statements

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

99封情书 提交于 2019-12-30 06:00:13
问题 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. 回答1: 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. 回答2: There's no

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

£可爱£侵袭症+ 提交于 2019-12-30 06:00:11
问题 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. 回答1: 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. 回答2: There's no

VB.NET TO C# - Gridview Code behind for a search from a listbox w a stored procedure

折月煮酒 提交于 2019-12-24 21:33:33
问题 I am looking for the correct code behind syntax in C# for displaying Search Results from multiple parameters in Gridview. I just did something similar in VB.NET but I have to update a project in C#.NET and am unsure of: 1) the correct codebehind syntax in C#.NET (code in VB.NET) 2) how to specify multiple search paramaters in the case that a user selects multiple Insurance Plan parameters, Multiple Age parameters, and/or M from a Listbox 3) disable or enable the ability to select multiple

Binary Shift Differences between VB.NET and C#

最后都变了- 提交于 2019-12-18 13:15:33
问题 I just found an interesting problem between translating some data: VB.NET: CByte(4) << 8 Returns 4 But C#: (byte)4 << 8 Returns 1024 Namely, why does VB.NET: (CByte(4) << 8).GetType() return type {Name = "Byte" FullName = "System.Byte"} Yet C#: ((byte)4 << 8).GetType() returns type {Name = "Int32" FullName = "System.Int32"} Is there a reason why these two treat the binary shift the same? Following from that, is there any way to make the C# bit shift perform the same as VB.NET (to make VB.NET