473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to initialize "public const short[] test"?

I can't do
public const short[] test = new short[]{1000,2000,3000};

any suggestions?

thx


Nov 15 '05 #1
4 2004
babylon wrote:
any suggestions?


public readonly short[] test = new short[] {1000, 2000, 3000};

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2
oic ...
then it should be
public static readonly short[] test = new short[] {1000, 2000, 3000};
as a const member is static

thank you!
any suggestions?


public readonly short[] test = new short[] {1000, 2000, 3000};

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)

Nov 15 '05 #3
If you have a really complicated init that you need to run for a const
member, you can write a static method which returns the result.

private static short[] InitTest() {
short[] res = null;
// do lots of complicated stuff here
return res;
}
public const short[] test = InitTest();

--Don

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"babylon" <am***@hotmail.com> wrote in message
news:Os**************@TK2MSFTNGP12.phx.gbl...
I can't do
public const short[] test = new short[]{1000,2000,3000};

any suggestions?

thx

Nov 15 '05 #4
Don Dumitru [MSFT] <do***@online.microsoft.com> wrote:
If you have a really complicated init that you need to run for a const
member, you can write a static method which returns the result.

private static short[] InitTest() {
short[] res = null;
// do lots of complicated stuff here
return res;
}
public const short[] test = InitTest();


No you can't, because "const" can't apply to arrays. Even if it could,
it *really* couldn't apply to something like the above, as "const"s are
meant to be *compile-time* constants.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: heinquoi | last post by:
hello, i have the code: class window { static const HWND hWnd; static const HINSTANCE hInst; // ... next code here window (HINSTANCE ); }
12
by: zealotcat | last post by:
template <class T> inline T const& max (T const& a, T const& b) { // if a < b then use b else use a return a<b?b:a; } thanks very much!!
11
by: snnn | last post by:
On the book <Generic Programming and the STL>( Matthew . H . Austern ),this function is defined as iterator set::begin() const. However, why should a const object returns a non-const iterator?...
0
by: Benjamin Lukner | last post by:
Hi! I'd like to dynamically call API functions from different DLLs, depending on what platform the program runs. Now I'm wondering what the most simple way may be (without meta code and compiler...
4
by: C. J. Clegg | last post by:
A month or so ago I read a discussion about putting const ints in header files, and how one shouldn't put things in header files that allocate memory, etc. because they will generate multiple...
0
by: Simon | last post by:
Hi All, I have come across a problem with a bog std MFC app linking to bog std MFC extension dll - both generated by the wizards. The code is set out below. The trouble is with the static...
26
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg");...
4
by: jaime | last post by:
Hi again all. Given the line: const int x=5; Can I then use "x" as a constant expression? (By "constant expression", I mean "constant expression" as defined in the C99 standard) I've been...
4
by: adam.timberlake | last post by:
Me again! I am trying to create a currency converter function for my eCommerce that still pet treats. I am a little short on money recently and so cannot afford a programmer. Can somebody tell me...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.