Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what the new mean in the following

Tags:

c#

.net

In the interface, I saw the following

  public interface ITest : ITestBase
    {
        new string Item { get; set; }
    }

I want to know the meaning of "new" here.

like image 903
user496949 Avatar asked Feb 15 '11 08:02

user496949


People also ask

What is mean by following?

transitive verb. 1 : to go, proceed, or come after followed the guide. 2a : to engage in as a calling or way of life : pursue wheat-growing is generally followed here. b : to walk or proceed along follow a path. 3a : to be or act in accordance with follow directions.

What is the new mean math?

The mean of a set of numbers, sometimes simply called the average , is the sum of the data divided by the total number of data. Example 1 : When a number x is added to the data set 4, 8, 20, 25, 32, the new mean is 15 . Find the value of x . Including x , there are 6 numbers in the set.

What is mean median and mode with example?

Example: The median of 4, 1, and 7 is 4 because when the numbers are put in order (1 , 4, 7) , the number 4 is in the middle. Mode: The most frequent number—that is, the number that occurs the highest number of times.

What is the mean of 25 observation is 27?

Mean of given observations = sum of given observations/ total number of observationsMean of 25 observations = 27∴ Sum of 25 observations = 27 × 25 = 675If 7 is subtracted from every number then the sum = 675 – 25 × 7 = 675 – 175 = 500Then new mean = 500/25 = 20Thus the new mean will be 20.


1 Answers

The new keyword in front of a property or method is used to hide the member with the same name in a parent class that is not virtual, and is considered by many (including me) bad practice because it may in many cases don't give you the result you expect.

An example:

class A{
  public int Test(){ return 1; }
}

class B : A{
  public new int Test(){ return 2; }
}

B b = new B();
Console.WriteLine( b.Test() );
A b2 = new B();
Console.WriteLine( b2.Test() );

This will print 2 and 1 respectively, and is confusing since both objects are in fact of type B.

like image 63
Øyvind Bråthen Avatar answered Oct 20 '22 01:10

Øyvind Bråthen