473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can't use String[] as const

Why can't I do this:

private const String[] words = new String[] {
"house",
"car"};

Nov 16 '05 #1
3 971
John Bailo <ja*****@earthlink.net> wrote:
Why can't I do this:

private const String[] words = new String[] {
"house",
"car"};


Because

new String[] { "house, "car" }

cannot be computed at compile time. See
<http://www.jaggersoft.com/csharp_standard/8.7.1.htm> for details.

The usual practise here would be to use:

static readonly

instead.

See also:

http://msdn.microsoft.com/library/de...c_10_4_2_1.asp
- or -
http://tinyurl.com/62p58
Nov 16 '05 #2
"John Bailo" <ja*****@earthlink.net> wrote:
Why can't I do this:
private const String[] words = new String[]
{ "house", "car"};


I'm not quite sure, but it will work if you use readonly instead of
const.

P.
Nov 16 '05 #3
Paul E Collins <fi******************@CL4.org> wrote:
"John Bailo" <ja*****@earthlink.net> wrote:
Why can't I do this:
private const String[] words = new String[]
{ "house", "car"};


I'm not quite sure, but it will work if you use readonly instead of
const.


That depends on what you mean by "work". Making it readonly won't stop
you from doing:

words[0] = "foo";

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

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

Similar topics

8
by: DrBob | last post by:
gcc 3.3 MAC OS X. I have a string that has trailing spaces in it that I want removed. So i have a variable: string x("abcd "); x.trim() isn't an implemented method. Is there a method I...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
11
by: lovecreatesbeauty | last post by:
Hello experts, Is const_cast only applied to pointers or references? If I have a constant object, then how can I remove constant attribute from it? #include <vector> #include <string>...
3
by: bwalke | last post by:
I was wondering how the Process.Start() command can be used in a VB.NET Web Application. I have used this command in a Windows Application before successfully. I want the client side to envoke the...
2
by: ES Kim | last post by:
Hi everyone, Sometimes I need to tokenize a string and convert it into some value. For example, "123.45" with predifined width 2/4 and type int/double should be converted into an int 2 and a...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
9
by: incredible | last post by:
how to sort link list of string
8
by: key9 | last post by:
Hi All I defined a class "RootElement" And want the class can be inherit tree's root. The main idea is using std::string as the "config" of the instance the module pass the compile with the...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.