Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Eventhandle !!!

Eventhandle !!!

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RongNK
    wrote on last edited by
    #1

    When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !

    W L L 3 Replies Last reply
    0
    • R RongNK

      When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      breakvn wrote:

      Use of unassigned local variable 'j'

      J doesn't have a value when you are registering the event. First assign a value for j (and i).

      The need to optimize rises from a bad design.My articles[^]

      modified on Thursday, January 8, 2009 11:26 AM

      R 1 Reply Last reply
      0
      • R RongNK

        When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !

        L Offline
        L Offline
        Le centriste
        wrote on last edited by
        #3

        Did you assign Label instances in your array? Initializing the array initializes all members to null.

        1 Reply Last reply
        0
        • R RongNK

          When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          breakvn wrote:

          Use of unassigned local variable 'j'

          means j has no value yet (it is local, hence not initially zero), yet you are already reading and using it. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Love, happiness and fewer bugs for 2009!


          1 Reply Last reply
          0
          • W Wendelius

            breakvn wrote:

            Use of unassigned local variable 'j'

            J doesn't have a value when you are registering the event. First assign a value for j (and i).

            The need to optimize rises from a bad design.My articles[^]

            modified on Thursday, January 8, 2009 11:26 AM

            R Offline
            R Offline
            RongNK
            wrote on last edited by
            #5

            Thank . So ,can you tell me how to use eventhander ... I need detail . Thank :)

            W 1 Reply Last reply
            0
            • R RongNK

              Thank . So ,can you tell me how to use eventhander ... I need detail . Thank :)

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              You could try something like (don't mind about the typos):

              Label tempLabel;

              for (int i = 0; i<20; i++) {
              for (int j = 0; j<20; j++) {
              tempLabel = new Label();
              tempLabel.Click += new System.EventHandler(ClickLabel)
              life[i,j] = tempLabel;
              }
              }

              The need to optimize rises from a bad design.My articles[^]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups