将盒子装入int64到int

时间:2017-08-07 21:26:24

标签: .net c++-cli

在泛型类方法中,我有以下代码:

page-home {
    p {
        text-align-last: center;
    }
}

Examplo:

在运行时的某个时刻,我的类与System::Object^ ObjectValue; // ... T Value = (T)ObjectValue; 实例化为Tint包含ObjectValue,但上面代码中的强制转换操作给了我一个System::Int64。我怎样才能使这个演员工作?

1 个答案:

答案 0 :(得分:2)

您遇到的问题将在没有泛型的情况下发生:

section {
    width: 400px;
    margin: 100px 0 0 50px;
}

.progParent {
    width: inherit;
    background-color:#000; 
    padding: 1px;
    position: relative;
}

.progChild {
    height: 10px;
    background-color: red;
    animation:mov 5s linear infinite alternate;
    width: 0%;
    float: left;
}

.progParent:after {
    clear: both;
    content: '';
    display: block;
}

.txt {
    position: absolute;
    top: -60px;
    white-space: nowrap;
    background-color: #000;
    color: orange;
    border: 1px solid #FFF;
    margin-left: -25px;
    padding:0;
    font-weight: bold;
    width: 50px;
    height: 50px;
    border-radius: 100%;
    line-height: 50px;
    text-align: center;
}

.arrow:before {
    content: '';
    width: 0;
    height: 0;
    border:5px solid;
    border-color: #000 transparent transparent transparent;
    bottom: -9px;
    left: 20px;
    position: absolute;
}

.rig {
    right: 0;
}

@keyframes mov {
    from {width: 0}
    to {width: 100%;background-color: green}
}

修改一次转换为unbox然后再转换为:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
<section>
    <div class="progParent">
        <div class="progChild"></div>
        <span class="txt arrow">0%</span>
    </div>
</section> 

使用Convert.ChangeType从未知的盒装类型进行强制转换:

Int64 x64 = 1;
Object^ boxed64 = x64;
int x32 = (int)boxed64;  // InvalidCastException

对于泛型:

int x32 = (int)(Int64)boxed64;  // works