计算5个文本框的总和 [英] Calculation of the sum of 5 textboxes

查看:100
本文介绍了计算5个文本框的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有五个文本框,我想将键入的值添加到其中,以计算所有五个值的总和.我正在使用ASP.net.

请在此指导我!

I have five textboxes and I want to add the values typed into them calculating the sum of all five values. I''m using ASP.net.

Please guide me in this!

推荐答案

在这里让您入门:

Here to get you started:

public Object Parse(String stringValue, Type typ)
{
    Type[] parseParams = new Type[] { typeof(String) };
    Object retVal = null;
    // This method should also check that the Parse method matches the type, but I'll leave that as an excercise
    MethodInfo mi = typ.GetMethod("Parse", parseParams);
    if (mi != null)
    {
        retVal = mi.Invoke(this, new Object[] { stringValue });
    }
    return retVal;
}

private D GetValue<D>(Textbox tb)
{
    D result = default(D);
    try
    {
        result = (D)Parse(tb.Text, typeof(D));
    }
    catch
    {
    }
    return result;
}

private T DoSum<T>(Textbox[] textboxes)
{
    T result = default(T);
    foreach(Textbox tb in textboxes)
    {
        result = Add<T>(result, GetValue<T>(tb));
    }
}

private L Add<L>(L result, L addend)
{
    L result = default(L);
    ...
    ...
    ...
    return result;
}



干杯!

—MRB



Cheers!

—MRB


这篇关于计算5个文本框的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆