\t in c#

A

alikha

I am doing Win32 interop. i have a library and the
example they have given is in vb.net. i am doing my
development in c# which does not seem to be working. i
have couple of questions what i am seeing the
difference between the supplied vb.net code and c#
code that i am doing:
------------------------
1. vb.net code is not using DLLImport Attribute when
defining the method. they use the Lib Keyword, for
example:

Public Declare Function SetWindowsHookEx Lib "user32"

What i have seen so far, this is simply another way to
do win32 interop in vb.net, instead of using the
dllimport attribute. Is this correct?

2. methods in the dll needs string parameters, and if
you have to send multiple values, it asks that the
values be separated by a tab character inside a single
string.

vb code shows this:

char tab = Char(9)
string param = "xyz" & tab & "abc";

if you set a break point and see param in vs.net
debugger, its shows:
"xyz abc" and shows the tab as a box kind of
character.
------------------------------------
when i do the same thing in C#, either using \t
between the values, or declaring a tab character as
its done in vb.net:

char tab = (chr)9;
string param = "xyz" + tab + "abc"
OR
string param = "xyz\tabc";

debugger and command windows show "xyz\tabc".

can anyone shed some light on this, why its different
behavior for the languages for seemingly same thing,
and if its not right, how can it be fixed?

Thanks
Ali
 
J

James Curran

Your code is correct. Your C# debugger is just smart enough to
translate the tab character into "\t" when it displays it in a watch window.
 
J

Jon Skeet [C# MVP]

if you set a break point and see param in vs.net
debugger, its shows:
"xyz abc" and shows the tab as a box kind of
character.
------------------------------------
when i do the same thing in C#, either using \t
between the values, or declaring a tab character as
its done in vb.net:

char tab = (chr)9;
string param = "xyz" + tab + "abc"
OR
string param = "xyz\tabc";

debugger and command windows show "xyz\tabc".

can anyone shed some light on this, why its different
behavior for the languages for seemingly same thing,
and if its not right, how can it be fixed?

It's the debuggers showing it differently.

See http://www.pobox.com/~skeet/csharp/strings.html#debugger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top