How to convert C++ code to C#

  • Thread starter Thread starter creatigent
  • Start date Start date
C

creatigent

How to convert this code to C#, Thanks

char ID[21];

ID[20]='\0';

srand((long) time(NULL));

char Result[43];

// ID 1-3
memcpy(Result,ID,3);

// 2 random digits
sprintf(&Result[3],"%2.2d",rand()%100);
 
How to convert this code to C#, Thanks

char ID[21];

ID[20]='\0';

srand((long) time(NULL));

char Result[43];

// ID 1-3
memcpy(Result,ID,3);

// 2 random digits
sprintf(&Result[3],"%2.2d",rand()%100);

Random rng = new Random();
string result = "***" + String.Format("{0:2}",rng.Next(100));

where "***" is replacing the 3 uninitialized bytes
containing random bytes from the stack in the C++ code.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top