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. Other Discussions
  3. Article Writing
  4. how to assign value Same variable name in base class and derived class C#

how to assign value Same variable name in base class and derived class C#

Scheduled Pinned Locked Moved Article Writing
csharptutorial
2 Posts 2 Posters 6 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
    rajendra sharma
    wrote on last edited by
    #1

    public class clsb
    {
    public string subjectName = "";
    public string mainsubject()
    {
    return subjectName;

        }
    }
    

    public class clsA : clsb
    {
    public string subjectName = "";
    public string Allsubject()
    {
    return subjectName;
    }
    }

    private void getdata()
        {
                 clsA obj = new clsA();
                obj.subjectName = "English";
                string A2 = obj.mainsubject();
                MessageBox.Show(A2);
    

    }

    L 1 Reply Last reply
    0
    • R rajendra sharma

      public class clsb
      {
      public string subjectName = "";
      public string mainsubject()
      {
      return subjectName;

          }
      }
      

      public class clsA : clsb
      {
      public string subjectName = "";
      public string Allsubject()
      {
      return subjectName;
      }
      }

      private void getdata()
          {
                   clsA obj = new clsA();
                  obj.subjectName = "English";
                  string A2 = obj.mainsubject();
                  MessageBox.Show(A2);
      

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This forum is for questions and comments about articles you have written, not for general questions. Please use either the C# Discussion Boards[^] or https://www.codeproject.com/Questions/ask.aspx[^].

      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