vb.net-to-c#

C# internal VS VBNET Friend

旧时模样 提交于 2019-12-12 10:29:46
问题 To this SO question: What is the C# equivalent of friend?, I would personally have answered "internal", just like Ja did among the answers! However, Jon Skeet says that there is no direct equivalence of VB Friend in C#. If Jon Skeet says so, I won't be the one telling otherwise! ;P I'm wondering how can the keyword internal (C#) not be the equivalent of Friend (VBNET) when their respective definitions are: Friend VBNET The Friend (Visual Basic) keyword in the declaration statement specifies

C# : Excel : Determine if a string is a valid Range reference?

核能气质少年 提交于 2019-12-12 02:06:23
问题 How would this VB function will look like as C# ? The goal is to determine if a string ref represents a valid datasheet Excel.Range . This isn't a trivial VB to C# conversion as Range can't be constructed. Private Function IsRange(ref) As Boolean ' Returns True if ref is a Range Dim x As Range On Error Resume Next Set x = Range(ref) If Err = 0 Then IsRange = True Else IsRange = False End Function Best 回答1: I would have liked to find a way to not have to rely on an exception for checking the

Where to write the functions of ApplicationEvents.vb when converting project to C#

耗尽温柔 提交于 2019-12-11 12:17:08
问题 I am trying to convert a VB.NET project to C#. I am conveting all the forms and classes as required, but I don't know where I need to write the events from ApplicationEvents.vb (I believe its autoGenerated from Properties) Here is the code in my ApplicationEvent.vb file: Imports GM.Powertrain.RemoteCopy.Interfaces Imports System.Runtime.Remoting.Channels.Tcp Imports System.Runtime.Remoting.Channels Namespace My Partial Friend Class MyApplication Private Shared serviceConfig As ServiceConfig =

IntelliSense for XElement objects with XML schema

ぃ、小莉子 提交于 2019-12-11 05:29:31
问题 Reading an article called "Increase LINQ Query Performance" in July's MSDN magazine, the author states that using an Imports in VB providing a path to schema in the current project will turn IntelliSense on for XElement. In the code provided, he uses statements like xelement.@name to retreive attributes values and so on. I did not try this out myself in VB but I would like to use that in C#. This really looks like LINQ to XSD. Is there any equivalent in C#? It seems that it is not possible to

Alternative to VB.NET's Type Conversion functions (CBool) in C#?

梦想与她 提交于 2019-12-04 04:00:32
问题 Is there any alternative to VB's CBool keyword in C#? What about all the other functions? CBool will turn to a Boolean any valid boolean: 0 , "False" , null etc. 回答1: The trick is that the Cxx "functions" in VB.NET aren't actually functions . In fact, they're more like operators that the compiler translates to what it determines is the "best-match" type conversion. Paul Vick used to have a great article about this on his blog, but all those pages seem to have been taken down now. MSDN (which

Equivalent of Format of VB in C#

╄→гoц情女王★ 提交于 2019-12-04 03:13:14
问题 What will be the equivalent code for Format(iCryptedByte, "000") (VB.NET) in C# ? 回答1: Try: iCryptedByte.ToString("D3"); 回答2: String.Format(format, iCryptedByte); // where format like {0:D2} See MSDN 1, 2, 3 回答3: Another very useful site for C# string formatting: http://blog.stevex.net/string-formatting-in-csharp/ Instead of {0:D3} you can also use the zero placeholder, e.g. {0:000} will pad with zeros to minimum length of three. 回答4: Given this VB code: Strings.Format(iCryptedByte, format)

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

谁说胖子不能爱 提交于 2019-12-04 01:51:19
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? I've found that VB programmers often littered code with many On Error Resume Next statements out of (bad) habit. My suggestion would be to start with no suppressed exceptions, and see what actually

Hex format in C# [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-02 23:49:03
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: C# - Convert a string of hex values to hex I converted the following code from Visual Basic to C#. But how do I know how I can use Hex in C#? private string ConvertStringToHex(string sText) { int lCount; string sHex; string sResult; for (lCount = 1; (lCount <= sText.Length); lCount++) { sHex = Hex(Convert.ToInt32(sText.Substring((lCount - 1), 1))); if ((sHex.Length == 1)) { sHex = ("0" + sHex); } sResult =

Alternative to VB.NET's Type Conversion functions (CBool) in C#?

孤街浪徒 提交于 2019-12-01 19:27:27
Is there any alternative to VB's CBool keyword in C#? What about all the other functions? CBool will turn to a Boolean any valid boolean: 0 , "False" , null etc. The trick is that the Cxx "functions" in VB.NET aren't actually functions . In fact, they're more like operators that the compiler translates to what it determines is the "best-match" type conversion. Paul Vick used to have a great article about this on his blog, but all those pages seem to have been taken down now. MSDN (which is mostly accurate here) says: These functions are compiled inline, meaning the conversion code is part of

Equivalent of Format of VB in C#

南楼画角 提交于 2019-12-01 16:47:20
What will be the equivalent code for Format(iCryptedByte, "000") (VB.NET) in C# ? Try: iCryptedByte.ToString("D3"); String.Format(format, iCryptedByte); // where format like {0:D2} See MSDN 1 , 2 , 3 Another very useful site for C# string formatting: http://blog.stevex.net/string-formatting-in-csharp/ Instead of {0:D3} you can also use the zero placeholder, e.g. {0:000} will pad with zeros to minimum length of three. Given this VB code: Strings.Format(iCryptedByte, format) Replace with this C# code: var csformat = "{0:" + format + "}"; String.Format(csformat, iCryptedByte); see String.Format