Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a new developer of c sharp. please told me how i convert it into csharp.
VB
Private Function DecryptPassWord(ByVal PassWord As String) As String
       Dim i As Integer
       Dim dcrpChar, dcrpString As String
       dcrpChar = ""
       dcrpString = ""
       For i = 1 To Len(PassWord)
           dcrpChar = 275 - Asc(Mid(PassWord, i, 1))
           dcrpString = Chr(dcrpChar) & dcrpString
       Next i
       DecryptPassWord = dcrpString
   End Function
Posted
Updated 17-Oct-12 6:13am
v2
Comments
[no name] 17-Oct-12 12:11pm    
Either use one of the online converters or it should be a trivial matter for you to do it yourself.

There are lots of free converters, few are:
Convert C# to VB.NET [^]
Convert C# to VB.NET2[^]
Code Translation for .NET [^]
Convert VB to C# or C# to VB[^]
Try it yourself!
 
Share this answer
 
Comments
Akinmade Bond 17-Oct-12 14:01pm    
Nice, hadn't known bout those. Thanks.
Sandeep Mewara 17-Oct-12 14:51pm    
Welcome.
ridoy 17-Oct-12 14:34pm    
good links,+5 always..:)
Sandeep Mewara 17-Oct-12 14:51pm    
Thanks ridoy. :)
To convert C# code to VB.Net or vice versa, you may need the following tools.

Language Convert.

Language convert is a simple plug-in for Visual Studio 2010 and 2012 allows you to convert VB.net code to C# and VB.net in C#.

Convert

Convert by FishCodeLib.com is a (6-in-1) integrated, powerful, multi-purpose conversion and developer tool that can also convert C# code to VB.Net and vice versa.

Developerfusion converter.

DeveloperFusion is a free web based utility that automatically converts C# to its equivalent in VB.NET and vice-versa, it allows you zip and entire project and convert it.

VB.Net to C# converter.[^]

This a shareware(not free) desktop application. Their claim
VBconversions.com says:
The Most Accurate VB.Net to C# Converter Money Can Buy
And they've got some testimonials too. ;)


And for a do it 'myself' way? You can start from the following links, CP has one too, kinda old though.

Complete Comparison for VB.NET and C#[^]

A Code project article that explains about advantages, differences and new features of VB.NET and C#. Last Updated. 18 Apr 2005

Comparison For C# and VB.Net[^]

A wiki article that explains the similarities, history and differences between C# and VB.Net.

Vb.Net and C# comparison[^]

For further reading....

For more articles, try GOOGLE.[^]

Okay, are you still here? Your code in VB.Net

VB
Private Function DecryptPassWord(ByVal PassWord As String) As String
       Dim i As Integer
       Dim dcrpChar, dcrpString As String
       dcrpChar = ""
       dcrpString = ""
       For i = 1 To Len(PassWord)
           dcrpChar = 275 - Asc(Mid(PassWord, i, 1))
           dcrpString = Chr(dcrpChar) & dcrpString
       Next i
       DecryptPassWord = dcrpString
   End Function


translates to in C# as

...First, in your code, the code Asc(Mid(PassWord, i, 1)). You should know that the functions Asc() and Mid() are not available, the first thing you should do is import Microsoft.VisualBasic so, in your using statements, you should add
C#
using Microsoft.VisualBasic;
Now, your code would be....

C#
private string decryptpassword(string password)
{
  string dcrpChar, dcrpString;
  dcrpChar="";
  dcrpString="";
  for (int i=1; i<=password.Length(); i+=1)
  {
           dcrpChar = 275 - Asc(PassWord.Substring( i, 1));
           //For the line above, you could use.
           //dcrpChar = 275 - Microsoft.VisualBasic.Asc(PassWord.Substring(i, 1));
           dcrpString = (Char)dcrpChar + dcrpString;
   }
  return dcrpString;
}
 
Share this answer
 
v2
Comments
ridoy 17-Oct-12 14:35pm    
+5
Hi,

Here's a link to a webpage where you can convert VB.NET to C#:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
 
Share this answer
 
C#
private string decryptpassword(string password)
{
  int i;
  string dcrpChar, dcrpString;
  dcrpChar="";
  dcrpString="";
  for (int i=1; i<=password.Length(); i+=1)
  {
           dcrpChar = 275 - Asc(PassWord.Substring( i, 1)); // check the ascii function, it might not be available in c#
           dcrpString = (Char)dcrpChar + dcrpString;
   }
  return dcrpString;
}
 
Share this answer
 
I'm assuming you're translating a whole VB application to C#, you are not using native code interop, and you have no passwords encrypted with this routine stored anywhere, if so, any of these translations should work for you (they are equivalent):
C#
static private string DecryptPassword(string PassWord)
{
    int i;
    string dcrpString = "";

    for (i = 0; i < PassWord.Length; i++)
        dcrpString = (char)(275 - PassWord[i]) + dcrpString;
    return dcrpString;
}

C#
static private string DecryptPassword(string PassWord)
{
    int i;
    string dcrpString = "";

    for (i = PassWord.Length - 1; i >= 0; i--)
        dcrpString += (char)(275 - PassWord[i]);
    return dcrpString;
}

Please note, if you call a VB routine that uses strings from C# (through Interop) I think this won't work because VB stores strings different from .NET (if I remember correctly).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900