vb to c# dll

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What's a good way to get to these groups dotnet.languages.vb and csharp,
I hate scrolling the udl.

I'd also like to see my references in a folder in the solution explorer
like I used
to in VS2005. The references are no longer visible for some reason unless I
use
project references.

Main question:

I'm using a referenced C# .dll in my vb.net project.
I'm trying to pass a string containing a filepath from a vb.net forms
application to a C# dll function. When I step to the C# function my string
suddenly has extra backslashes. In C# I tried using the replace function
fileName.Replace("\\", "\");
but I got three errors, 1. newline in constant, ) and ; expected.

Suggestions appreciated.
 
Hello segue,

In C# (like C++ before it), the \ character is an escape character. In other
words, they expect the \ to be followed by another character to tell what
character to actually show. For example, I can do this in C#:

string s = "He said, \"Hello THere\"";

The \" tells the string to put an actual quote in my text. One of the most
common escape sequences you will see with \ is \\. When you see \\ in your
C# code, its the same as seeing \ in your VB.NET code. You can jsut treat
it as a single slash. Don't worry about seeing it in the C# code...its
normal...don't try and fix it.


Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
 
The extra backslashes are just escaped single backslashes, you should not
try to replace them :-)

You can use verbatim string literals if you want to avoid escaping

string aString = @"\Hello \new world\" which produces the same as string foo
= "\\Hello \\new world\\"

but expect to see \\ in debugger. That's how it works (I guess this can be
changed somewhere in the settings)
 
Oh the shame. Well thanks.

Lebesgue said:
The extra backslashes are just escaped single backslashes, you should not
try to replace them :-)

You can use verbatim string literals if you want to avoid escaping

string aString = @"\Hello \new world\" which produces the same as string foo
= "\\Hello \\new world\\"

but expect to see \\ in debugger. That's how it works (I guess this can be
changed somewhere in the settings)
 
Back
Top