Typing question - page 6

 
As far as I remember, C# is not a good friend of mql
 
Ilya Malev:
As far as I remember, C# is not good friends with mql

https://www.mql5.com/ru/forum/285631

10. MQL5: Added native support for .NET libraries with "smart" function import. Now you can use .NET libraries without writing special wrappers - MetaEditor takes care of that.

Новая версия платформы MetaTrader 5 build 1930: Плавающие окна графиков и .Net библиотеки в MQL5
Новая версия платформы MetaTrader 5 build 1930: Плавающие окна графиков и .Net библиотеки в MQL5
  • 2018.10.25
  • www.mql5.com
26 октября 2018 года будет выпущена обновленная версия платформы MetaTrader 5...
 
Not calling to write in C#. Just that the benefits of implicit conversion are questionable (imho, sugar, no more), it does not increase profitability of strategies. If anyone can explain why it helps so much when coding strategies, I would be happy to learn something new.
 
Vasiliy Sokolov:
It doesn't increase the profitability of strategies.

Referring to the profitability of strategies when discussing programming techniques is rather depressing.

Vasiliy Sokolov:
If someone can explain why it helps so much in coding - I'll be glad to learn something new.

You can't even make your own multidimensional array properly. Let alone an array with different types of values. You can't even do it with just one, because such code would not fit into mql:

  Array array;

  double d=123.456;

  array[5]=d;

  d=array[5];

Of course, you can write d=array[5].to_double(), pretend it should be so and be happy about your ugly code. But if overloading of type conversion operations were allowed, hardly anyone would prefer this way of writing d=array[5].

 
Ilya Malev:

...

of course you can write d=array[5].to_double(), pretend that this is how it should be and be happy about your buggy code. But if overloading of type conversion operations were allowed, hardly anyone would prefer this way of writing d=array[5].

Straightforward. d=array[5] could:

template <typename T>
class MainArray
{
private:
   T m_items[];
   int m_curr;
public:
   MainArray()
   {
      ArrayResize(m_items, 16);
      m_curr = 0;
   }
   void Add(T item)
   {
      m_items[m_curr++] = item;
   }
   T operator[](int index)
   {
      return m_items[index];
   }
};
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   MainArray<double> array;
   array.Add(123.456);
   double v = array[0];
   printf((string)v);
}

If we get nerdy, there are still difficulties with array[3] = 4.00123; But it's readable and fine as it is.

 
Vasiliy Sokolov:

Right. d=array[5] is fine:

If you get boring, then there are difficulties with array[3] = 4.00123; But it's readable and good enough as it is.

Yep, d=array[5] is ok. but then you can't make array[5]=d. But you can make %= instead of =. no problem, at the same time the icon will remind us what place everything is done through))

 
Ilya Malev:

Yeah, d=array[5] can. but then you can't make array[5]=d. But you can make %= instead of =. No problem, and the icon will remind you which place to use))

If you really want to do it, you can do it like this

#property strict

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

#define  PRINT(A) ::Print(#A + " = " + (string)(A));

void OnStart( void )
{
// Работа со стандартными типами
  color Color = C'241,248,255';

  PRINT(_R(Color)[(uchar)1])             // Green-составляющая цвета - 248

  _W(Color)[2] = (uchar)230;             // Записали по смещению 2 значение (uchar)230.
  PRINT(Color)                           // Убедились, что Color теперь C'241,248,230'

// Работа со строками
  string Str = "abcd";

  _W(Str)[2] = "98765";                  // Побайтовая запись строки в строку со смещением 2
  PRINT(Str)

  string StrArray[] = {"123", "45", "6789"};
  _W(Str) = StrArray;                    // Записали в строку строковый массив
  PRINT(Str)

  _W(Str)[3] = (uchar)0;                 // В байт со смещением 3 записали ноль, тем самым отбрезав строку (длина - 3 ANSI-символа (4 байта))
  PRINT(Str);
}

etc.

 
pavlick_:

I was critical at first too, but then I thought I could use it myself:

I asked for a parenthesis operator and a grapeshot operator about three or four years ago.

you ask, maybe you can do better.

 
It's a shame you can't add pluses to your posts.)
 
Ilya Malev:

...

of course you can write d=array[5].to_double(), pretend that this is how it should be and be happy about your buggy code. But if overloading of type conversion operations were allowed, hardly anyone would prefer this way of writing d=array[5].

What problems people have))) Oh, bless my life!

By the way, writingd=array[5].to_double() is much easier thand=(double)array[5] Just press a point. But we're not looking for easy ways...