Efficient 'constant' char arrays?

  • Thread starter Thread starter Ian Oliver
  • Start date Start date
I

Ian Oliver

Are these declarations compiled into the object or executed at runtime?

// easy to write
char[] NumericChars = "0123456789.,".ToCharArray();

// cumbersome to type
char[] NumericChars = {'0','1','2','3','4','5','6','7','8','9','.',','};

TIA, Ian
 
// easy to writ
char[] NumericChars = "0123456789.,".ToCharArray();

Converted to array of char at runtime however you can make a const like version of this using a static readonly var that is initialized once and thereafter is constant..
// cumbersome to typ
char[] NumericChars = {'0','1','2','3','4','5','6','7','8','9','.',','}

Compiled... And alternatively this is compiled if you don't mind using Unicode than type "char"

const string NumericChars = "0123456789.,"

--Richar
 

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