IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

méthode OfType() ne fonctionne pas


Sujet :

C#

  1. #1
    maa
    maa est déconnecté
    Membre actif
    Avatar de maa
    Inscrit en
    Octobre 2005
    Messages
    672
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Octobre 2005
    Messages : 672
    Points : 288
    Points
    288
    Par défaut méthode OfType() ne fonctionne pas
    Bonjour,

    Ces 2 code me retournent des résultats différents :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
                var _ContentPlaceHolders = new List<RichTextContentControl>();
                foreach (object c in Controls)
                    if (c.GetType() == typeof(RichTextContentControl))
                        _ContentPlaceHolders.Add((RichTextContentControl)c);
     
                MessageBox.Show(_ContentPlaceHolders.Count.ToString());
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
                MessageBox.Show(Controls.OfType<RichTextContentControl>().Count().ToString());
    Le premier me renvois 1, le second 0. Je ne vois vraiment pas pourquoi le second ne fonctionne pas.

    Quelqu'un aurait une idée ?

    Merci d'avance.

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Je viens de tester avec ce code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    int i = 0;
     
                foreach (object c in this.Children)
                {
                    if (c.GetType() == typeof(TextButton))
                    {
                        i++;
                    }
                }
     
                int r = this.Children.OfType<TextButton>().Count();
    i et r valent bien 1 à la fin...

  3. #3
    maa
    maa est déconnecté
    Membre actif
    Avatar de maa
    Inscrit en
    Octobre 2005
    Messages
    672
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Octobre 2005
    Messages : 672
    Points : 288
    Points
    288
    Par défaut
    Oui mais pas avec le type RichTextContentControl dans un projet VSTO

  4. #4
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Certes, mais je ne vois pas ce que cela changerait....

  5. #5
    maa
    maa est déconnecté
    Membre actif
    Avatar de maa
    Inscrit en
    Octobre 2005
    Messages
    672
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Octobre 2005
    Messages : 672
    Points : 288
    Points
    288
    Par défaut
    Je comprends pas moi non plus... mais le fait est que ça ne marche pas. J'essaie de comprendre pourquoi. Tu peux tester de ton côté stp ?

  6. #6
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Faudra que je teste ASAP.

  7. #7
    maa
    maa est déconnecté
    Membre actif
    Avatar de maa
    Inscrit en
    Octobre 2005
    Messages
    672
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Octobre 2005
    Messages : 672
    Points : 288
    Points
    288
    Par défaut
    Tu as pu tester ?

  8. #8
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Nop, pas eu le temps dernièrement

Discussions similaires

  1. méthode stringToKenizer() ne fonctionne pas
    Par Nayra dans le forum Langage
    Réponses: 8
    Dernier message: 20/11/2010, 22h00
  2. Réponses: 4
    Dernier message: 27/08/2010, 11h45
  3. [XL-2003] Méthode Copy ne fonctionne pas
    Par sagitarium dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 30/09/2009, 13h58
  4. Méthode objet ne fonctionne pas (4D 2003)
    Par Jimmy Jazz dans le forum 4D
    Réponses: 7
    Dernier message: 18/09/2009, 14h03
  5. Ma méthode ajouter ne fonctionne pas
    Par beegees dans le forum C++
    Réponses: 6
    Dernier message: 14/05/2008, 15h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo