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.