[VB.NET > C#.NET] Vertalen

Pagina: 1
Acties:
  • 45 views sinds 30-01-2008

  • UniCache2
  • Registratie: Januari 2001
  • Laatst online: 02-03 09:30
Ik heb al even gezocht en onderandere deze converter gebruikt: http://www.codeproject.com/csharp/gbvb.asp, maar zonder resultaat.

Ik zou zelf deze code van VB.NET:

code:
1
2
3
4
5
6
7
8
9
10
11
' Create an array of role names
  Dim roleList As New ArrayList
  Do While reader.Read()
      roleList.Add(reader("sGroupName"))
  Loop
  
  'Convert the roleList ArrayList to a String array
  Dim roleListArray As String() = roleList.ToArray(GetType(String))
  
  'Add the roles to the User Principal
  HttpContext.Current.User = New GenericPrincipal(User.Identity, roleListArray)


Zo vertalen:

code:
1
2
3
4
5
6
7
8
9
10
11
12
//Create an array of role names
ArrayList roleList = new ArrayList();
while(oReader.Read()) {
  roleList.Add(oReader.GetSqlString(0));
}

//Convert the roleList ArrayList to a String array
//string[] sRoleListArray = roleList.ToArray(GetType("string"));
string sRoleListArray = roleList.ToArray(System.Type.GetType("System.String"));

//Add the roles to the User Principal
HttpContext.Current.User = new GenericPrincipal(HttpContext.Current.User.Identity, sRoleListArray);


Ik krijg nu echter een fout "Cannot implicitly convert type 'System.Array' to 'string'" op de regel van roleList.ToArray

En in de laatste regel: "Argument '2': cannot convert from 'string' to 'string[]'"

Iemand een idee?

  • Woy
  • Registratie: April 2000
  • Niet online

Woy

Moderator Devschuur®
Je krijgt ook een Array terug en niet een enkele string. Hoezo heb je de regel waar je string[] hebt staan uitgecommentarieerd?

“Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.”


Verwijderd

string[] sRoleListArray = (string[])roleList.ToArray(typeof(string) );

  • whoami
  • Registratie: December 2000
  • Laatst online: 15:14
sRoleListArray heb je niet als string gedefinieerd.
Logisch nadenken, fouten interpreteren, ....

https://fgheysels.github.io/


Dit topic is gesloten.