Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can one class set a property to be seen by another c
Message
De
27/02/2013 04:02:08
 
 
À
27/02/2013 03:45:18
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01566989
Message ID:
01567010
Vues:
48
This message has been marked as a message which has helped to the initial question of the thread.
>>Hi everybody,
>>
>>In the base class I defined a public property with simple
>>
>>Public InvokeString {get;set;}
>>
>>I have two classes that inherit from that main class. In one of the classes I have a method where I can set this property. My problem is that I want another class to be able to read that new property value.
>>
>>Is there a way to solve it? Should I use static keyword here for the property only?
>
>Not sure I understand your requirement but I don't see how 'static' would help. Maybe something like this?:
    public  class ClassA
>	{
>        protected  virtual string InvokeString { get; set; }
>	}
>
>    public class ClassB : ClassA
>    {
>        public void SetInvokeString(string s)
>        {
>            base.InvokeString = s;
>        }
>        
>        public new string InvokeString
>        {
>            get { return base.InvokeString; }
>        }
>    }
I don't see how static can be of any help either - static is not instance related

How about restricting the setter in classB ?

But to set it is a bit weird
	public static class qqq
	{
		static void Main()
		{
			ClassB xx = new ClassB();

			((ClassA)xx).InvokeString = "hello";
			string pp = xx.InvokeString;

			

		}
}
	public class ClassA
	{
		public virtual string InvokeString { get; set; }
	}

	public class ClassB : ClassA
	{

		public new string InvokeString
		{
			get { return base.InvokeString; }
		}
	
		
	}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform