Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

what does "override" do in c#?

Name: Anonymous 2007-12-11 11:48

what does "override" do in c#?

Name: Anonymous 2007-12-11 11:51

ask your book idiot

Name: Anonymous 2007-12-11 12:00

Read K&R.

Name: Anonymous 2007-12-11 12:01

Read SICP

Name: Anonymous 2007-12-11 13:38

Read MSDN.

Name: Anonymous 2007-12-11 15:17

Read Vogue.

Name: Anonymous 2007-12-11 15:22

Read Ender's Game, by Orson Scott Card. Me and my friends really like it!

Name: Anonymous 2007-12-11 16:35

Read Foundation, by Isaac Asimov, the mad Russian.

I learned programming from it.

Name: Anonymous 2007-12-11 16:37

>>7
I've heard of him, but looking through his bookography, I can't think why

Name: Anonymous 2007-12-12 4:26

Read Green Eggs and Ham, by Dr. Seuss.

Name: LOL 2007-12-12 12:21

Name: Anonymous 2007-12-12 13:34

Read Google

Name: Anonymous 2007-12-12 19:14

>>12
All of it?

Name: Anonymous 2007-12-12 19:34

>>1
overrides a method defined in the base class.

Name: Anonymous 2007-12-12 22:20

>>13
No, just the bits related to 'overide' in C# silly

Name: Anonymous 2007-12-13 8:15

It takes an abstract function and makes your new function override the behavior of the previous function. It also does this in such a way that any class that extends your new class will not be able to change that particular function in any way.

Make sense?

Name: Anonymous 2007-12-13 17:26

17.5.4 Override methods

When an instance method declaration includes an [tt]override[/tt] modifier, the method is said to be an override
method
. An override method overrides an inherited virtual method with the same signature. Whereas a
virtual method declaration introduces a new method, an override method declaration specializes an existing
inherited virtual method by providing a new implementation of that method.

The method overridden by an [tt]override[/tt] declaration is known as the overridden base method. For an
override method [tt]M[/tt] declared in a class [tt]C[/tt], the overridden base method is determined by examining each base
class of [tt]C[/tt], starting with the direct base class of [tt]C[/tt] and continuing with each successive direct base class, until
an accessible method with the same signature as [tt]M[/tt] is located. For the purposes of locating the overridden
base method, a method is considered accessible if it is [tt]public[/tt], if it is [tt]protected[/tt], if it is [tt]protected
internal[/tt], or if it is [tt]internal[/tt] and declared in the same program as [tt]C[/tt].

A compile-time error occurs unless all of the following are true for an override declaration:
• An overridden base method can be located as described above.
• The overridden base method is a virtual, abstract, or override method. In other words, the overridden base method cannot be static or non-virtual.
• The overridden base method is not a sealed method.
• The override declaration and the overridden base method have the same return type.
• The override declaration and the overridden base method have the same declared accessibility. In other words, an override declaration cannot change the accessibility of the virtual method.

An override declaration can access the overridden base method using a base-access (§14.5.8). [Example: In
the following code

class A
{
    int x;
    public virtual void PrintFields() {
        Console.WriteLine("x = {0}", x);
    }
}
class B: A
{
    int y;
    public override void PrintFields() {
        base.PrintFields();
        Console.WriteLine("y = {0}", y);
    }
}

the [tt]base.PrintFields()[/tt] invocation in [tt]B[/tt] invokes the [tt]PrintFields[/tt] method declared in [tt]A[/tt]. A base-access
disables the virtual invocation mechanism and simply treats the base method as a non-virtual method.
Had the invocation in [tt]B[/tt] been written [tt]((A)this).PrintFields()[/tt], it would recursively invoke the
[tt]PrintFields[/tt] method declared in [tt]B[/tt], not the one declared in [tt]A[/tt], since [tt]PrintFields[/tt] is virtual and the runtime
type of [tt]((A)this)[/tt] is [tt]B[/tt]. end example]

Only by including an [tt]override[/tt] modifier can a method override another method. In all other cases, a
method with the same signature as an inherited method simply hides the inherited method. [Example: In the
following code

class A
{
    public virtual void F() {}
}
class B: A
{
    public virtual void F() {} // Warning, hiding inherited F()
}

the [tt]F[/tt] method in [tt]B[/tt] does not include an [tt]override[/tt] modifier and therefore does not override the [tt]F[/tt] method
in [tt]A[/tt]. Rather, the [tt]F[/tt] method in [tt]B[/tt] hides the method in [tt]A[/tt], and a warning is reported because the declaration does
not include a new modifier. end example]

[Example: In the following code

class A
{
    public virtual void F() {}
}
class B: A
{
    new private void F() {} // Hides A.F within B
}
class C: B
{
    public override void F() {} // Ok, overrides A.F
}

the [tt]F[/tt] method in [tt]B[/tt] hides the virtual [tt]F[/tt] method inherited from [tt]A[/tt]. Since the new [tt]F[/tt] in [tt]B[/tt] has private access, its
scope only includes the class body of [tt]B[/tt] and does not extend to [tt]C[/tt]. Therefore, the declaration of [tt]F[/tt] in [tt]C[/tt] is
permitted to override the [tt]F[/tt] inherited from [tt]A[/tt]. end example]

C# spec 4tw :)
(hope I didn't fail formatting this post)

Name: Anonymous 2007-12-13 17:28

oh gawd..

17.5.4 Override methods

When an instance method declaration includes an override modifier, the method is said to be an override
method
. An override method overrides an inherited virtual method with the same signature. Whereas a
virtual method declaration introduces a new method, an override method declaration specializes an existing
inherited virtual method by providing a new implementation of that method.

The method overridden by an override declaration is known as the overridden base method. For an
override method M declared in a class C, the overridden base method is determined by examining each base
class of C, starting with the direct base class of C and continuing with each successive direct base class, until
an accessible method with the same signature as M is located. For the purposes of locating the overridden
base method, a method is considered accessible if it is public, if it is protected, if it is protected
internal
, or if it is internal and declared in the same program as C.

A compile-time error occurs unless all of the following are true for an override declaration:
• An overridden base method can be located as described above.
• The overridden base method is a virtual, abstract, or override method. In other words, the overridden base method cannot be static or non-virtual.
• The overridden base method is not a sealed method.
• The override declaration and the overridden base method have the same return type.
• The override declaration and the overridden base method have the same declared accessibility. In other words, an override declaration cannot change the accessibility of the virtual method.

An override declaration can access the overridden base method using a base-access (§14.5.8). [Example: In
the following code
class A
{
    int x;
    public virtual void PrintFields() {
        Console.WriteLine("x = {0}", x);
    }
}
class B: A
{
    int y;
    public override void PrintFields() {
        base.PrintFields();
        Console.WriteLine("y = {0}", y);
    }
}

the base.PrintFields() invocation in B invokes the PrintFields method declared in A. A base-access
disables the virtual invocation mechanism and simply treats the base method as a non-virtual method.
Had the invocation in B been written ((A)this).PrintFields(), it would recursively invoke the
PrintFields method declared in B, not the one declared in A, since PrintFields is virtual and the runtime
type of ((A)this) is B. end example]

Only by including an override modifier can a method override another method. In all other cases, a
method with the same signature as an inherited method simply hides the inherited method. [Example: In the
following code
class A
{
    public virtual void F() {}
}
class B: A
{
    public virtual void F() {} // Warning, hiding inherited F()
}

the F method in B does not include an override modifier and therefore does not override the F method
in A. Rather, the F method in B hides the method in A, and a warning is reported because the declaration does
not include a new modifier. end example]

[Example: In the following code
class A
{
    public virtual void F() {}
}
class B: A
{
    new private void F() {} // Hides A.F within B
}
class C: B
{
    public override void F() {} // Ok, overrides A.F
}

the F method in B hides the virtual F method inherited from A. Since the new F in B has private access, its
scope only includes the class body of B and does not extend to C. Therefore, the declaration of F in C is
permitted to override the F inherited from A. end example]

C# spec 4tw :)
fix'd, I hope

Name: Anonymous 2007-12-13 18:45

>>17
lrn2teletype, faggot.

Name: Anonymous 2007-12-13 19:07

>>19
no YOU do it

Name: Anonymous 2009-03-18 2:46

The word pirahna, is all I can think of that rhymes with marijuana

Marijuana MUST be legalized.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List