Errors, bugs, questions - page 2690

 

Hi.

What could be the error? I place two copies of the same indicator on the chart, I change the colour of the lines in the first indicator, the colour of the lines also changes in the second, but I do not change anything in the second. There are no global variables.

 
Nikolai Semko:

I don't see any logic in it.
For simple types, firstly, you can do so:

secondly, it is:

and it's not all crutches.

result in both cases:

17*256+92=4444

The logic is that if you can write data into an array for structures within one function, it should be the same for simple types.

Okay, the situation here is quite simple.

 
Aliaksandr Hryshyn:

The logic is that if data can be written to an array for structures within a function, it should be the same for simple types.

I'd like to confirm this logic with something other than your opinion.

google "C# struct to byte array" if you're interested.

Note that C# is a brainchild of Microsoft for all non-programmers, and what in MQL is done in a couple of lines, in C#, in fact, simply not provided - in googled examples everything is done via Marshal, and this is work with unmanaged code, that is, it's outside of .Net - in MQL terms - "this is a .dll call".


that's how it's logical...

 
Igor Makanu:

I'd like to confirm this logic with something other than your opinion.

google "C# struct to byte array" if you're interested.

Note that C# is a brainchild of Microsoft for all non-programmers, and what in MQL is done in a couple of lines, in C#, in fact, simply not provided - in googled examples everything is done via Marshal, and this is work with unmanaged code, that is, it's outside of .Net - in MQL terms - "it's a call of a .dll".


That's how it's logical...

There's a lot of that in there:

BinaryWriter.Write Method

Lots of overloaded methods:

Write(UInt64)   
Write(UInt32)   
Write(UInt16)
.....
 
Aliaksandr Hryshyn:

There's such a thing:

Lots of overloaded methods:

https://metanit.com/sharp/tutorial/5.6.php

This is analogous to working with files in MQL with flag FILE_BIN

If I'm not mistaken, you didn't want to work with files, but just serialize a simple data type into a byte array

 
Igor Makanu:

https://metanit.com/sharp/tutorial/5.6.php

This is analogous to working with files in MQL with flag FILE_BIN

If I'm not mistaken, you want to serialize a simple data type into a byte array

FileStream

MemoryStream

Both files and memory.

Why do you have such a dislike for C# :)?
 
Aliaksandr Hryshyn:

FileStream

MemoryStream

Both files and memory.

Why do you have such a dislike towards C# :)?

About the hostility you invented, I just wrote that the language is for non-programmers, which corresponds to a very friendly to the user, to be specific

about file streams, you've made a simple task quite complicated

The essence of my question to you is that MQL is a very advanced language in terms of "raw data" processing, one more example - MQL has no default structure alignment, it's convenient for users

 
Igor Makanu:

I just wrote that the language is for non-programmers, which corresponds to a very user-friendly, to be specific

about file streams, you've made a simple task quite complicated

The essence of my question to you is that MQL is a very advanced language in terms of "raw data" processing, one more example - MQL has no default structure alignment, it's convenient for users

There's an analogue of a file stream only in the RAM.
 
Aliaksandr Hryshyn:
There is an analogue of file stream only in RAM.

Why? Mostly simple types can be converted to bytes this way:

void OnStart()
{
   int i_value = 123456;
   uchar arr_byte[4];
   arr_byte[0] = (uchar)(i_value & 0x000000FF);
   arr_byte[1] = (uchar)((i_value & 0x0000FF00) >> 8);
   arr_byte[2] = (uchar)((i_value & 0x00FF0000) >> 16);
   arr_byte[3] = (uchar)((i_value & 0xFF000000) >> 32);
   ArrayPrint(arr_byte);

// проверим собрав обратно из байт int

   union _int
   {
      int i;
      uchar c[sizeof(int)];
   } ui;
   ArrayCopy(ui.c, arr_byte);
   Print(ui.i);
}

this code (first part) should work in C# as well, at least I never had any problems with integer types, it seems like variant #3 already

you can wrap my code in a loop to make it a bit more compact

UPD:

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i_value = 123456;
            uint mask = 0x000000FF;
            byte[] arr_byte = new byte[4];
            for(int i=0; i<4; i++)
            {
                arr_byte[i] = (byte)((i_value & mask) >> i*8);
                mask <<= 8;
                Console.WriteLine(arr_byte[i]);
            }
            Console.ReadLine();
        }
    }
}
 
Igor Makanu:

Note that C# is the brainchild of Microsoft for all non-programmers, and what in MQL is done in a couple of lines in C#, in fact, is simply not provided for

Indeed! And "non-programmers" don't know for some reason that it's "not provided for".
Files:
Reason: