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. about dynamic change a expressions in methods

about dynamic change a expressions in methods

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 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.
  • C Offline
    C Offline
    clj19870503
    wrote on last edited by
    #1

    hello, for example, i have three Textbox and a button int the Form(textBox1,textBox2,textBox3, button2). private void button2_Click(object sender, EventArgs e) { int temp; temp = int.Parse(textBox2.Text) + int.Parse(textBox1.Text); textBox3.Text = temp.ToString(); } A question is : i have two roles (system administrator and commmon user) in this software. if i have written this button2_Click(), can i let system administrator change button2_Click() when software is running. eg,temp = int.Parse(textBox2.Text) * int.Parse(textBox1.Text); instead of temp = int.Parse(textBox2.Text) + int.Parse(textBox1.Text); thank you

    J 1 Reply Last reply
    0
    • C clj19870503

      hello, for example, i have three Textbox and a button int the Form(textBox1,textBox2,textBox3, button2). private void button2_Click(object sender, EventArgs e) { int temp; temp = int.Parse(textBox2.Text) + int.Parse(textBox1.Text); textBox3.Text = temp.ToString(); } A question is : i have two roles (system administrator and commmon user) in this software. if i have written this button2_Click(), can i let system administrator change button2_Click() when software is running. eg,temp = int.Parse(textBox2.Text) * int.Parse(textBox1.Text); instead of temp = int.Parse(textBox2.Text) + int.Parse(textBox1.Text); thank you

      J Offline
      J Offline
      Jimmanuel
      wrote on last edited by
      #2

      Sure you can. The simplest way is to use a boolean (see below) but there are more complex and elaborate methods if there is a lot of role dependent behavior in your system.

      bool isAdmin = false; // TODO: set this to an actual value on startup
      private void button2_Click(object sender, EventArgs e)
      {
      int temp;
      if (isAdmin)
      {
      temp = int.Parse(textBox2.Text) * int.Parse(textBox1.Text);
      }
      else
      {
      temp = int.Parse(textBox2.Text) + int.Parse(textBox1.Text);
      }
      textBox3.Text = temp.ToString();
      }

      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