using Microsoft.VisualBasic in c#

  • Thread starter Thread starter Avon
  • Start date Start date
A

Avon

Hi friends,

Probably stupid question,

Is it wrong or dangerous if I use some vb.net functions in c# via
Microsoft.VisualBasic namespase? For example:

Int32 a = Microsoft.VisualBasic.Strings.Asc("z");

Console.WriteLine(a);



It is working, but I am wondering is it safe to use it?
 
It is .NET managed code and is part of the framework. Don't be afraid of the
namespace's name. Use it away.
 
Its safe to use.

However, in case you wonder,the equivalent to your code in C# is:

int Asc(char ch)
{
//Return the character value of the given character
return (int)Encoding.ASCII.GetBytes(S)[0];
}
 
However, in case you wonder,the equivalent to your code in C# is:
int Asc(char ch)
{
//Return the character value of the given character
return (int)Encoding.ASCII.GetBytes(S)[0];
}

Careful! ASCII is _not_ character encoding used by the Asc() function in the VB assembly... Accoring to the docs, the line should probably look something like this:

return (int)Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture..TextInfo.ANSICodePage).GetBytes(S)[0];
 
| Hi friends,
|
| Probably stupid question,
|
| Is it wrong or dangerous if I use some vb.net functions in c# via
| Microsoft.VisualBasic namespase? For example:
|
| Int32 a = Microsoft.VisualBasic.Strings.Asc("z");
|
| Console.WriteLine(a);
|
|
|
| It is working, but I am wondering is it safe to use it?
|
|

It's not wrong nor dangerous, but that doesn't mean it's the right thing to
do.
Don't forget that you will load the Microsoft.VisualBasic.dll into your
process, this is quite expensive when all you need is to call 'Asc'.

Willy.
 
Back
Top