how to override the properties in child project

青春壹個敷衍的年華 提交于 2019-12-25 10:58:22

问题


I am working on Windows Phone app Development,

I have 3 projects

1) Library Project

2) Child Project 1 referencing the library project

3) Child Project 2 referencing the library project

In Library project it contains all xaml files,.cs files etc... In my child project it contain only a MainPage.xaml and its .cs file where I am navigating it to a page in my library project.

But there are few condition in my library project code and it will work based on those conditions like :

In my library project a class can contain:

if(language == "JAVA"){
  // alert with text as "Android"
}else{
 // alert with text as "Windows"
}

here the string JAVA might be defined in library project like this:

public String LanguageName(){
  return "JAVA";
}

But in my child project it can be override like:

public override String LanguageName(){
      return "C#";
    }

So when I execute in should show me a alert with Windows as text , if its not defined in child project then it should alert with default value as Android.

How to achieve this ?


回答1:


To override a method, the base method must be virtual:

// in base class
public virtual String LanguageName(){
  return "JAVA";
}


// in derived class
public override String LanguageName(){
  return "C#";
}


来源:https://stackoverflow.com/questions/21290249/how-to-override-the-properties-in-child-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!