I have a property ProductName in my Form. I am getting warning while compiling the code.
FormInventory.ProductName hides inherited member ‘System.Windows.Forms.Control.ProductName'. Use the new keyword if hiding was intended.
below is my code
public partial class FormInventory : Form, IInventoryView
{
public FormInventory()
{
}
public string ProductName
{
get { return this.textProductName.text; }
set { this.textProductName.text = value; }
}
}
textProductName is a textbox.
I know that ProductName hides the base class’s property Forms.Control.ProductName. My question is
-
Is it possible to suppress the warning without Renaming my
FormInventory.ProductNameproperty -
I am currently in the beginning of the development, if i hide this property with the
newmodifier will there be any problem at the time of releasing the product, because base propertyForms.Control.ProductNamereturns the product name of the assembly containing the control. Where as myFormInventory.ProductNamereturns a user entered value. -
Where will we be using this
Forms.Control.ProductName, because i have never used it before.
I have searched and found Similar questions
these questions doesn’t solve my problem but helped me in understanding the cause for the warning.
1. Yes, simply use the
newkeyword, likepublic new string ProductName { get; set; }2. No, it simply returns the name of the assembly.
3. Its used for debugging and some “reflection”. I say “reflection” because it’s more like a human-made reflection.
So, it’s safe to go forward this way. But why don’t you simply change it to
MyCompanyProductName?Regards