小编Mil*_*711的帖子

如何从int创建引用类型

我试过了:

int i = 5;
object o1 = i; // boxing the i into object (so it should be a reference type)
object o2 = o1; // set object reference o2 to o1 (so o1 and o2 point to same place at the heap)

o2 = 8; // put 8 to at the place at the heap where o2 points
Run Code Online (Sandbox Code Playgroud)

运行此代码后,o1中的值仍为5,但我预计为8.

我错过了什么吗?

.net c#

7
推荐指数
2
解决办法
1万
查看次数

调用超超类的方法

当每个类都包含具有相同名称的方法时,在访问层次结构中的方法时遇到麻烦。

class A { 
    constructor(private name: string) { }
    notify() { alert(this.name) }
}

class B extends A { 
    constructor() {
        super("AAA")
    }

    notify() {alert("B") }
}

class C extends B { 
    notify() { alert("C") }

    callA() {
        this.notify(); // this alerts "C"
        super.notify(); // this alerts "B"

        // How to call notify() of the class A so it alerts "AAA"? 
    }
}

new C().callA();
Run Code Online (Sandbox Code Playgroud)

inheritance typescript ecmascript-6

1
推荐指数
2
解决办法
885
查看次数

标签 统计

.net ×1

c# ×1

ecmascript-6 ×1

inheritance ×1

typescript ×1