473,386 Members | 1,779 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,386 software developers and data experts.

character array question

Hi there,

Could anyone let me know what the c's are for in this statement:
Private Shared hexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c,
"6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}

Thanks!

-Ben
Dec 23 '05 #1
8 6901

"Ben R." <be**@newsgroup.nospam> wrote in message
news:45**********************************@microsof t.com...
: Hi there,
:
: Could anyone let me know what the c's are for in this statement:
:
:
: Private Shared hexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c,
: "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
:
: Thanks!
:
: -Ben
The Char type is a numeric type, not a string type. The string character "F"
is not a Char. Since this statement is initializing an array of Char types,
you can't just add string literals. The 'c' identifies to the compiler that
this is to be treated as a Char, not a one character string.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.

Dec 23 '05 #2
Ben,

A char is a one postition Unicode.

The ""c tells that something is a char and not a single char immutable
string (and therefore the lenght is known).

A string is an immutable string of char (immutable is not changeble itself
it will always be copied)
A stringbuilder is a muttable string of char.

I hope this helps,

Cor
Dec 24 '05 #3
"Ben R." <be**@newsgroup.nospam> schrieb:
Could anyone let me know what the c's are for in this statement:
Private Shared hexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c,
"6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}


The suffix 'c' marks the literals as 'Char' literals opposed to 'String'
literals.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 24 '05 #4
Ben,
As the other suggest, the "c" in "0"c means that its a Char literal zero
character, and not a String literal zero character. For details see:

http://msdn2.microsoft.com/en-us/library/7sx7t66b.aspx

http://msdn2.microsoft.com/en-us/library/thwcx436.aspx
FWIW: The statement could also have been written:

Private Shared hexDigits As Char() =
"0123456789ABCDEF".ToCharArray()

Which although may be shorter (both source wise & IL wise), may be more
obscure for some developers.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Ben R." <be**@newsgroup.nospam> wrote in message
news:45**********************************@microsof t.com...
| Hi there,
|
| Could anyone let me know what the c's are for in this statement:
|
|
| Private Shared hexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c,
| "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
|
| Thanks!
|
| -Ben
Dec 24 '05 #5
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb:
FWIW: The statement could also have been written:

Private Shared hexDigits As Char() =
"0123456789ABCDEF".ToCharArray()

Which although may be shorter (both source wise & IL wise), may be more
obscure for some developers.


Mhm. I am curious what the overhead of calling 'ToCharArray' is -- but here
it's christmas eve.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 24 '05 #6
Herfried,
| > Which although may be shorter (both source wise & IL wise), may be more
| > obscure for some developers.
| Mhm. I am curious what the overhead of calling 'ToCharArray' is

Actually the "overhead" is in the array initializer, not the ToCharArray!
;-)

In VB 2005 (Debug & Release builds) the IL for the ToCharArray is
significantly shorter, 3 lines of IL. While the IL for the Array initializer
is 70+ lines of IL building the array itself. Both initialization code is
placed in a shared constructor...

I use both depending on the problem at hand, I consider it largely personal
preference, some problem domain... I would only worry about performance
overhead, once profiling indicated that there was a performance problem...

Given:

Public Class Constants
Private Shared hexDigits1 As Char() =
"0123456789ABCDEF".ToCharArray()
Private Shared hexDigits2 As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c,
"5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
End Class

Produces the following IL:

..method private specialname rtspecialname static
void .cctor() cil managed
{
// Code size 118 (0x76)
.maxstack 3
.locals init ([0] char[] VB$t_array$S0)
.language '{3A12D0B8-C26C-11D0-B442-00A0244A1DD2}',
'{994B45C4-E6E9-11D2-903F-00C04FA302A1}',
'{5A869D0B-6611-11D3-BD2A-0000F80849BD}'
// Source File 'C:\...\MainModule.vb'

//000104: Private Shared hexDigits1 As Char() =
"0123456789ABCDEF".ToCharArray()
IL_0000: ldstr "0123456789ABCDEF"
IL_0005: callvirt instance char[]
[mscorlib]System.String::ToCharArray()
IL_000a: stsfld char[] ....MainModule/Constants::hexDigits1

//000105: Private Shared hexDigits2 As Char() = {"0"c, "1"c, "2"c,
"3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c,
"F"c}
IL_000f: ldc.i4.s 16
IL_0011: newarr [mscorlib]System.Char
IL_0016: stloc.0
IL_0017: ldloc.0
IL_0018: ldc.i4.0
IL_0019: ldc.i4.s 48
IL_001b: stelem.i2
IL_001c: ldloc.0
IL_001d: ldc.i4.1
IL_001e: ldc.i4.s 49
IL_0020: stelem.i2
IL_0021: ldloc.0
IL_0022: ldc.i4.2
IL_0023: ldc.i4.s 50
IL_0025: stelem.i2
IL_0026: ldloc.0
IL_0027: ldc.i4.3
IL_0028: ldc.i4.s 51
IL_002a: stelem.i2
IL_002b: ldloc.0
IL_002c: ldc.i4.4
IL_002d: ldc.i4.s 52
IL_002f: stelem.i2
IL_0030: ldloc.0
IL_0031: ldc.i4.5
IL_0032: ldc.i4.s 53
IL_0034: stelem.i2
IL_0035: ldloc.0
IL_0036: ldc.i4.6
IL_0037: ldc.i4.s 54
IL_0039: stelem.i2
IL_003a: ldloc.0
IL_003b: ldc.i4.7
IL_003c: ldc.i4.s 55
IL_003e: stelem.i2
IL_003f: ldloc.0
IL_0040: ldc.i4.8
IL_0041: ldc.i4.s 56
IL_0043: stelem.i2
IL_0044: ldloc.0
IL_0045: ldc.i4.s 9
IL_0047: ldc.i4.s 57
IL_0049: stelem.i2
IL_004a: ldloc.0
IL_004b: ldc.i4.s 10
IL_004d: ldc.i4.s 65
IL_004f: stelem.i2
IL_0050: ldloc.0
IL_0051: ldc.i4.s 11
IL_0053: ldc.i4.s 66
IL_0055: stelem.i2
IL_0056: ldloc.0
IL_0057: ldc.i4.s 12
IL_0059: ldc.i4.s 67
IL_005b: stelem.i2
IL_005c: ldloc.0
IL_005d: ldc.i4.s 13
IL_005f: ldc.i4.s 68
IL_0061: stelem.i2
IL_0062: ldloc.0
IL_0063: ldc.i4.s 14
IL_0065: ldc.i4.s 69
IL_0067: stelem.i2
IL_0068: ldloc.0
IL_0069: ldc.i4.s 15
IL_006b: ldc.i4.s 70
IL_006d: stelem.i2
IL_006e: ldloc.0
IL_006f: stsfld char[] ....MainModule/Constants::hexDigits2
IL_0074: nop
IL_0075: ret
} // end of method Constants::.cctor

| but here
| it's christmas eve.
Merry Christmas! Its Christmas Eve here also, well almost its 2:00 in the
afternoon as I write this... We'll start the celebrations in a few hours...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb:
| > FWIW: The statement could also have been written:
| >
| > Private Shared hexDigits As Char() =
| > "0123456789ABCDEF".ToCharArray()
| >
| > Which although may be shorter (both source wise & IL wise), may be more
| > obscure for some developers.
|
| Mhm. I am curious what the overhead of calling 'ToCharArray' is -- but
here
| it's christmas eve.
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
Dec 24 '05 #7
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb:
| > Which although may be shorter (both source wise & IL wise), may be
more
| > obscure for some developers.
| Mhm. I am curious what the overhead of calling 'ToCharArray' is

Actually the "overhead" is in the array initializer, not the ToCharArray!
;-)

In VB 2005 (Debug & Release builds) the IL for the ToCharArray is
significantly shorter, 3 lines of IL. While the IL for the Array
initializer
is 70+ lines of IL building the array itself. Both initialization code is
placed in a shared constructor...


Thank you for investigating. Merry Christmas :-)!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 24 '05 #8
Thanks to all for the thorough explanation!

-Ben

"Jay B. Harlow [MVP - Outlook]" wrote:
Ben,
As the other suggest, the "c" in "0"c means that its a Char literal zero
character, and not a String literal zero character. For details see:

http://msdn2.microsoft.com/en-us/library/7sx7t66b.aspx

http://msdn2.microsoft.com/en-us/library/thwcx436.aspx
FWIW: The statement could also have been written:

Private Shared hexDigits As Char() =
"0123456789ABCDEF".ToCharArray()

Which although may be shorter (both source wise & IL wise), may be more
obscure for some developers.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Ben R." <be**@newsgroup.nospam> wrote in message
news:45**********************************@microsof t.com...
| Hi there,
|
| Could anyone let me know what the c's are for in this statement:
|
|
| Private Shared hexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c,
| "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
|
| Thanks!
|
| -Ben

Dec 27 '05 #9

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

Similar topics

3
by: rl | last post by:
Hi out there, I'd like to know sth about the costs of a function call in php and the handling of character arrays (init size, enlargement steps of allocated memory, technique on enlargement ->...
8
by: dbuser | last post by:
Hi, I need help on a problem, as described below. I am reading a file "input.txt"which has data like this: abc def gh izk lmnopq rst uvwxyz I am using fstream object to read the file and...
14
by: Charles L | last post by:
I don't know if this is a stupid quesiton or not. I would like to know how to convert an array of characters generated from a previous operation to a string ie how do I append a null character at...
9
by: Christian Kandeler | last post by:
Hi, if I want to store the string "123456" in a variable of type char, I can do it like this: char s = "123456"; Or like this: char s = { '1', '2', '3', '4', '5', '6', '\0' };
6
by: funmachine | last post by:
Hi there, everyone! I'm a student studying computer animation. But alas, in order to graduate I have to take a programming class and it's kicking my butt. I have two projects left to write (and...
6
by: Kannan | last post by:
Hi, I have question about character array initialization. In section 6.7.8 paragraph number 21, it's given that "If there are fewer initializers in a brace-enclosed list than there are...
35
by: rajash | last post by:
Hello everyone, Thanks again for all the suggestions, though I think some people are a bit fussy in their answers. Here is a solution to Exercise 1.14. It deals well with control characters...
13
by: Ivan | last post by:
Hi, What is the best syntax to use a char to index into an array. /////////////////////////////////// For example int data; data = 1;
7
by: Keith Thompson | last post by:
"mkeles84" <mkeles84@hotmail.comwrites: comp.std.c deals with the C standard -- the document, how it's developed, and so forth. comp.lang.c deals with the C language, and that's where your...
19
by: bowlderyu | last post by:
Hello, all. If a struct contains a character strings, there are two methods to define the struct, one by character array, another by character pointer. E.g, //Program for struct includeing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.