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

Windows Forms Discussion :

[VB.NET] With...End With et performances ?


Sujet :

Windows Forms

  1. #1
    Dnx
    Dnx est déconnecté
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    290
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2003
    Messages : 290
    Points : 154
    Points
    154
    Par défaut [VB.NET] With...End With et performances ?
    bonjour je voulais savoir si c'est recommandé d'utiliser les WITH ... END WITH
    c'est plutot de l'esthétique? ou ca change un tantinet la performance?

    bien à vous

  2. #2
    Membre éprouvé
    Avatar de HULK
    Inscrit en
    Juillet 2003
    Messages
    1 274
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 274
    Points : 1 280
    Points
    1 280
    j'suis vert !

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 92
    Points : 114
    Points
    114
    Par défaut
    Ca ne change rien à la performance à mon avis.
    C'est simplement pour faciliter la syntaxe.

  4. #4
    Membre éprouvé
    Avatar de HULK
    Inscrit en
    Juillet 2003
    Messages
    1 274
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 274
    Points : 1 280
    Points
    1 280
    Par défaut
    With.. End With accélère le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    With Form1.TextBox1
        .BackColor= Red
        .Text="BoBo"
        .Visible= True
    End With
    est plus rapide que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Form1.TextBox1.BackColor= Red
    Form1.TextBox1.Text="BoBo"
    Form1.TextBox1.Visible= True
    car Form1.TextBox1 est 'évalué' 3 fois au lieu de 1 fois
    j'suis vert !

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 92
    Points : 114
    Points
    114
    Par défaut
    Je viens de lire l'article dont le lien est donné plus haut et je ne comprends pas trop:
    en effet, comment peut on dire que dans l'exemple donné, l'expression est évalué plusieurs fois sans le with et une seule fois avec.
    Une fois le code compilé, le with n'existe plus et est remplacé par la référence complète. Je me trompe?

  6. #6
    Membre éprouvé
    Avatar de HULK
    Inscrit en
    Juillet 2003
    Messages
    1 274
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 274
    Points : 1 280
    Points
    1 280
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    L'instruction With...End With permet d'appliquer une série d'instructions à l'objet spécifié, sans désigner à chaque fois le nom de l'objet. Par exemple, pour modifier plusieurs propriétés d'un seul objet, placez les instructions d'assignation de propriétés dans With...End With ; vous ne faites ainsi référence qu'une seule fois à l'objet, au lieu de le faire à chaque assignation de propriété. L'exemple ci-dessous illustre l'utilisation de l'instruction With...End With dans le cadre de l'assignation de valeurs à plusieurs propriétés d'un même objet
    http://msdn.microsoft.com/library/fre/default.asp?url=/library/FRE/vblr7/html/vastmWith.asp

    Fait des recherches tu trouvera tres certainement ta réponse
    j'suis vert !

  7. #7
    Expert éminent
    Avatar de neo.51
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    2 663
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Avril 2002
    Messages : 2 663
    Points : 6 418
    Points
    6 418
    Par défaut
    code 1 :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     Me.TextBox1.Text = "toto"
            Me.TextBox1.TextAlign = HorizontalAlignment.Center
            Me.TextBox1.Tag = "tata"
            Me.Visible = True
    IL
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    .method private instance void Form1_Load(object sender, [mscorlib]System.EventArgs e) cil managed
    {
          // Code Size: 58 byte(s)
          .maxstack 8
          L_0000: nop 
          L_0001: ldarg.0 
          L_0002: callvirt instance [System.Windows.Forms]System.Windows.Forms.TextBox testWith.Form1::get_TextBox1()
          L_0007: ldstr "toto"
          L_000c: callvirt instance void [System.Windows.Forms]System.Windows.Forms.TextBox::set_Text(string)
          L_0011: nop 
          L_0012: ldarg.0 
          L_0013: callvirt instance [System.Windows.Forms]System.Windows.Forms.TextBox testWith.Form1::get_TextBox1()
          L_0018: ldc.i4.2 
          L_0019: callvirt instance void [System.Windows.Forms]System.Windows.Forms.TextBox::set_TextAlign([System.Windows.Forms]System.Windows.Forms.HorizontalAlignment)
          L_001e: nop 
          L_001f: ldarg.0 
          L_0020: callvirt instance [System.Windows.Forms]System.Windows.Forms.TextBox testWith.Form1::get_TextBox1()
          L_0025: ldstr "tata"
          L_002a: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Tag(object)
          L_002f: nop 
          L_0030: ldarg.0 
          L_0031: ldc.i4.1 
          L_0032: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Visible(bool)
          L_0037: nop 
          L_0038: nop 
          L_0039: ret 
    }
    code 2
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With TextBox1
                .Text = "toto"
                .TextAlign = HorizontalAlignment.Center
                .Tag = "tata"
                .Visible = True
            End With
        End Sub
    IL
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    .method private instance void Form2_Load(object sender, [mscorlib]System.EventArgs e) cil managed
    {
          // Code Size: 52 byte(s)
          .maxstack 2
          .locals (
                [System.Windows.Forms]System.Windows.Forms.TextBox box1)
          L_0000: nop 
          L_0001: ldarg.0 
          L_0002: callvirt instance [System.Windows.Forms]System.Windows.Forms.TextBox testWith.Form2::get_TextBox1()
          L_0007: stloc.0 
          L_0008: ldloc.0 
          L_0009: ldstr "toto"
          L_000e: callvirt instance void [System.Windows.Forms]System.Windows.Forms.TextBox::set_Text(string)
          L_0013: nop 
          L_0014: ldloc.0 
          L_0015: ldc.i4.2 
          L_0016: callvirt instance void [System.Windows.Forms]System.Windows.Forms.TextBox::set_TextAlign([System.Windows.Forms]System.Windows.Forms.HorizontalAlignment)
          L_001b: nop 
          L_001c: ldloc.0 
          L_001d: ldstr "tata"
          L_0022: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Tag(object)
          L_0027: nop 
          L_0028: ldloc.0 
          L_0029: ldc.i4.1 
          L_002a: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Visible(bool)
          L_002f: nop 
          L_0030: ldnull 
          L_0031: stloc.0 
          L_0032: nop 
          L_0033: ret 
    }

  8. #8
    Dnx
    Dnx est déconnecté
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    290
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2003
    Messages : 290
    Points : 154
    Points
    154
    Par défaut
    on sent quand meme une legere performance apparemment
    merci a vous tous

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 92
    Points : 114
    Points
    114
    Par défaut
    Effectivement, au vu du code IL c'est clair
    Mais je ne comprends toujours pas
    Pourquoi cette fonctionnalité n'existe pas en C# si elle est plus performante?
    A moins que ce soit le compilo qui le fait de facon itelligente?

  10. #10
    Expert éminent
    Avatar de neo.51
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    2 663
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Avril 2002
    Messages : 2 663
    Points : 6 418
    Points
    6 418
    Par défaut
    Citation Envoyé par ld9474
    Pourquoi cette fonctionnalité n'existe pas en C# si elle est plus performante?
    On va pas relancer le débat C# VS VB.NET mais le With... end with ferait trop vbiste et pas assez "pro".

    Par contre en VB.NET il manquerait le @ de C#....


    la suite : http://www.developpez.net/forums/viewtopic.php?t=58595

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. With, End With ?
    Par benoît14 dans le forum Débuter
    Réponses: 8
    Dernier message: 30/01/2013, 12h36
  2. Utilité de With/End With ?
    Par OtObOx dans le forum Général VBA
    Réponses: 4
    Dernier message: 27/02/2011, 01h30
  3. Gerer les propriété d'un TextBox (With, end With)
    Par geeksideofme dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 02/07/2007, 17h57
  4. [VBA-E] Limitation des With...End With
    Par bernard38 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 27/10/2006, 15h59

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