Ctype

Résolu
cs_jorrie Messages postés 62 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 23 mai 2007 - 22 févr. 2007 à 13:50
cs_jorrie Messages postés 62 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 23 mai 2007 - 22 févr. 2007 à 17:26
Bonjours voila jai recuperer un bout de code qui est en VB.net et
j'aimerais le passé en C# mais je n'y arrive pas a retrouver les
correspondances :


voici le code VB:


  Dim col As NameValueCollection

        col =
CType(ConfigurationSettings.GetConfig("MyCustom/Servicing"),
NameValueCollection)

       
Console.WriteLine(col("Report1"))
        Dim hash As Hashtable

        hash = CType(ConfigurationSettings.GetConfig("MyCustom/Maintaining"), Hashtable)

        Console.WriteLine(hash("Page1"))


Mon principale probleme est de retrouver la correspondance Ctype est
C#, j'ai essaye avec Convert.ChangeType() mais ca marche pas

6 réponses

cs_jorrie Messages postés 62 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 23 mai 2007
22 févr. 2007 à 17:26
c'est bon j'ai trouve j'ai utilise ca :


//Appel

    PrintKeysAndValues( hash );


     ---------------------------------------------------------------


        public static void PrintKeysAndValues( Hashtable myList ) 

        {

            IDictionaryEnumerator myEnumerator = myList.GetEnumerator();

            Console.WriteLine( "\t-KEY-\t-VALUE-" );

            while ( myEnumerator.MoveNext() )

                MessageBox.Show(Convert.ToString(myEnumerator.Key));

       

        }


merci beaucoup de m'avoir aidé
3
jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 29
22 févr. 2007 à 16:14
bonjour, ctype est l'opérateur de cast. ctype(monObj, String) est équivalent à (String)monObj

<hr />Cyril - MVS - MCP
0
cs_jorrie Messages postés 62 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 23 mai 2007
22 févr. 2007 à 16:31
quand je fais ca :


    col = (NameValueCollection)(ConfigurationSettings.GetConfig("MyCustom/Servicing"));


il marque


 Jeton '=' non valide dans la déclaration de membres de la classe, structure ou interface
0
cs_jorrie Messages postés 62 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 23 mai 2007
22 févr. 2007 à 16:39
bien sur j'ai declaré

NameValueCollection col;   avant tout
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 29
22 févr. 2007 à 16:58
NameValueCollection coll = (NameValueCollection)(ConfigurationSettings.GetConfig("MyCustom/Servicing"));

devrait fonctionner, on peut voir un peu plus du code qui plante.

<hr />Cyril - MVS - MCP
0
cs_jorrie Messages postés 62 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 23 mai 2007
22 févr. 2007 à 17:07
 NameValueCollection coll = (NameValueCollection)(ConfigurationSettings.GetConfig("MyCustom/Servicing"));

       

 Hashtable hash = (Hashtable)(ConfigurationSettings.GetConfig("MyCustom/Maintaining"));

    

 MessageBox.Show(hash("Page1"));


Voici maintenant mon code, ceci c'est pour lire mon app.config, mais il
se trouve que j'ai une erreur au niveau de la 3eme ligne :


'hash' désigne 'variable' où 'méthode' était attendu
0
Rejoignez-nous