如何在asp.net c中转换多个度量转换# [英] How can u convert multiple measure conversion in asp.net c#

查看:62
本文介绍了如何在asp.net c中转换多个度量转换#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我已经开发了使用测量转换的web应用程序。我已经将英寸转换为英尺并且反之亦然。但是如何转换剩余转换,米,中心计,公里,英里,毫米,道路,弗隆。实际上我知道每个转换逻辑,但我不知道如何编写这种编程的方式只进行多次转换



我这样的代码



actually i have develop web application using measure conversion.i have convert the inches to feet and voice versa.but how to convert remaing conversions,meters,centermeters,kilometers,miles,millimeters,roads,furlongs.actually i know for each conversion logic but i do not know how to write way of this programming for multiple conversion only

my code like this

<form id="form1" runat="server">
    <div>
    
                                                                
        <asp:TextBox ID="TextBox1" runat="server" 
            style="top: 37px; left: 213px; position: absolute; height: 22px; width: 128px; right: 889px"></asp:TextBox>
          
        <br />
        <asp:TextBox ID="TextBox2" runat="server" 
            style="top: 39px; left: 510px; position: absolute; height: 22px; width: 128px"></asp:TextBox>
        <asp:DropDownList ID="DropDownList1" runat="server" 
            style="top: 37px; left: 351px; position: absolute; height: 22px; width: 77px">
            <asp:ListItem>Feet</asp:ListItem>
            <asp:ListItem>Miles</asp:ListItem>
            <asp:ListItem>Inches</asp:ListItem>
            <asp:ListItem>Meters</asp:ListItem>
            <asp:ListItem>Centimeters</asp:ListItem>
            <asp:ListItem>Millimeters</asp:ListItem>
            <asp:ListItem>rods</asp:ListItem>
            <asp:ListItem>Furlongs</asp:ListItem>
        </asp:DropDownList>
        <br />
  
        <br />
        <br />
        <br />
        <asp:DropDownList ID="DropDownList2" runat="server" 
            style="top: 36px; left: 652px; position: absolute; height: 22px; width: 77px">
            <asp:ListItem>Feet</asp:ListItem>
            <asp:ListItem>Miles</asp:ListItem>
            <asp:ListItem>Inches</asp:ListItem>
            <asp:ListItem>Meters</asp:ListItem>
            <asp:ListItem>centimeters</asp:ListItem>
            <asp:ListItem>millimeters</asp:ListItem>
            <asp:ListItem>rods</asp:ListItem>
            <asp:ListItem>furlongs</asp:ListItem>
        </asp:DropDownList>
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            style="top: 86px; left: 448px; position: absolute; height: 26px; width: 56px" 
            Text="convert" />
        <br />
        <br />
        <br />
    
    </div>
    </form>







这样的源代码






source code like this

using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication3
{
    public partial class WebForm1 : System.Web.UI.Page
    {           
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (DropDownList1.Text == "Feet")
            {
                double answer = Convert.ToDouble(TextBox1.Text) * 12.0;
                TextBox2.Text = answer.ToString();
            }
            if (DropDownList1.Text == "Inches")
            {
                double answer = Convert.ToDouble(TextBox1.Text) / 12.0;
                TextBox2.Text = answer.ToString();
            }          

        }
    }
}







i想要针对每次测量进行多次转换的解决方案




i want solution for multiple conversion about each measurement

推荐答案

您只需要以常规方式完成所有这些工作。



如果你想在基本测量中开发测量转换,比如长度,质量,时间,电荷,这几乎是直截了当的。如果要转换组合值,例如cm / sec或g /cm²(压力)等,将会更加困难;它需要对基础物理和思维的理解有所了解。现在,我将我的建议限制在最简单的情况下。



基本上,你需要开发一些代表一组的通用类测量单位(这是正确调用的方式)相同的物理尺度,例如长度。它可能是一些集合,或者可能是一个以上的集合,比如用名称标记的字典,以及另一个,比如转换因子。



这套装置的元素是什么?它应该是具有名称(厘米),缩写名称(cm)和相对于基本测量单位的转换因子等属性的类型,例如,1。集合类的每个实例都可以具有属性定义一个基本单位(它可以表示为其中一个元素的索引),其中一个转换因子为1.该集合的其他元素将具有相对于该基本测量单位的转换因子。



然后你应该创建这个集合类的几个实例(一个用于长度,另一个用于质量等),每个用测量单元填充。这将是您将用于所有单位变换的一般情况的基本结构,一般统一方法。您可以进一步开发此系统以处理综合物理措施。



-SA
You just need to do all this job in some regular way.

It is nearly straightforward if you want to develop measure conversion in basic measures, say, length, mass, time, electric charge. It's going to be much more difficult if you are going to convert combined values, such as cm/sec or g/cm² (pressure) and the like; it will need some understanding of basic physics and good deal of thinking. For now, I'll limit my advice to the idea of the simplest case.

Basically, you need to develop some universal class representing a set of the measurement units (this is how it is correctly called) of the same physical measure, such as length. It could be some collection, or, probably, more than one collections, like dictionaries indexed by, say, name, and, another one, say, conversion factor.

What would be the element of this set? It should be a type with such properties as name ("centimeters"), abbreviated name ("cm"), and a conversion factor relative to the base measurement unit, say, 1. Each instance of the set class can have a property defining a base unit (it could be expressed just as the index of one of the elements), the one of the conversion factor of 1. Other elements of the set will have conversion factors relative to this base measurement unit.

Then you should create several instances of this set class (one for length, another for mass, etc.), populate each with measurement units. This will be the basic structure you would use for all the general cases of unit transforms, general unified approach. You can further develop this system to deal with combined physical measures.

—SA


这篇关于如何在asp.net c中转换多个度量转换#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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