Talaviya Bhavdip

Talaviya Bhavdip

  • 494
  • 2.8k
  • 1.5m

I can't get value of base class field from child class object in c#

Dec 9 2020 6:43 AM
  1. using System;                     
  2. public class Program  
  3. {  
  4.     public static void Main()  
  5.     
  6.          CloudCollectionHelper cloudHelper = new CloudCollectionHelper();  
  7.          SlackHelper slackHelper = new SlackHelper();      
  8.         cloudHelper.DatabaseID=12345;  
  9.         Console.WriteLine(slackHelper.GetSlackPageTokens());
  10.     }
  11.     class CloudCollectionHelper  
  12.     {  
  13.         public  long DatabaseID { get; set; }     
  14.     }  
  15.     class SlackHelper:CloudCollectionHelper  
  16.     {  
  17.           
  18.         public long GetSlackPageTokens()  
  19.         {  
  20.             return DatabaseID;  
  21.         }  
  22.     }  
  23. }  
current output: 0 Expected Output: 12345
 
I need output 12345 because DatabaseID from the cloudhelper so i need that databaseID in the slackhelper.
 
this is my c# online compiler: https://dotnetfiddle.net/QNQeEX
 
I dont want to write something below because I have 1000+ field in the cloudhelper
  1. SlackHelper slackHelper = new SlackHelper();          
  2. slackHelper.DatabaseID=12345;  
  3. Console.WriteLine(slackHelper.GetSlackPageTokens());  
Thanks in advance.

Answers (2)