Hello. Can you please tell me what the code for working with units looks like?

Well, for example, you need to perform some algebraic operations on several numbers, expressed in certain units of measurement. And in the end you need to get not only the number, but also its unit of measurement. How does such an algorithm look like?

Closed due to the fact that the essence of the question is not clear by the participants user8694, null , Athari , aleksandr barakin , ixSci 21 Jul '15 at 5:06 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    @SuperAlexey, Please rephrase your question. - Drac5
  • four
    You have an error in the word "Code", instead of the letter "t" the letter "d" is written! :) - vv2cc

1 answer 1

If I correctly understood your problem, then you need to perform certain operations with numbers that can represent parameters in different units of measurement. The only thing is not clear where and how your units of measurement are indicated, so for now we’ll determine that some units of measurement are specified all the same initially but they need to be reduced to one factor, for example:

10м. + 30см. + 600мм. = 1м. + 0,3м. + 0,6м. = 1,9м. 

In this case I would suggest an object approach, i.e. each number is a successor of an interface like this:

 public interface INumInCI { /// <summary> /// заданное значение /// </summary> double Value { get; set; } /// <summary> /// текущий множитель /// </summary> double Factor { get; set; } /// <summary> /// Список множителей, например для метров /// 0.001, "мм." /// 0.01, "см." /// 0.1, "дм." /// 1, "м." /// 1000, "км." /// </summary> Dictionary<double, string> FactorList { get; set; } /// <summary> /// возвращает значение с множителеи 1 /// с учетом того что текущее значение и текущий множитель извесны /// </summary> /// <returns></returns> double Get_CI_Value(); } 

and to all this, it will be necessary to attach an editor to enter an expression indicating the entered values, or a good parser with checking the entered data, this is to your taste.