Out of curiosity, only, which is recommended for SHORT concatenation...or
concatenating two or three strings that are relatively small in size?
Dim a As String = "bah"
Dim b As String = "bah2"
Dim c As String = a & b
Dim d As String = String.Concat(a, b)
string a = "bah";
string b = "bah2";
string c = a + b;
string d = string.Concat(a, b);
Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method when
the size/number of strings is unknown?
Thanks,
Mythran 3 1405
Mythran <ki********@hotmail.comREMOVETRAIL> wrote: Out of curiosity, only, which is recommended for SHORT concatenation...or concatenating two or three strings that are relatively small in size?
Dim a As String = "bah" Dim b As String = "bah2" Dim c As String = a & b Dim d As String = String.Concat(a, b)
string a = "bah"; string b = "bah2"; string c = a + b; string d = string.Concat(a, b);
Like I said, doesn't really matter .. but sometimes I use one, and other times I use the other. Is there a recommended one? Should I use the concatenation operator (+/&) for small, known strings and Concat method when the size/number of strings is unknown?
They compile to the same code - the compiler uses String.Concat
internally. However, I believe that using the operator is usually more
readable than using string.Concat explicitly.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Mythran" <ki********@hotmail.comREMOVETRAIL> schrieb: Out of curiosity, only, which is recommended for SHORT concatenation...or concatenating two or three strings that are relatively small in size?
Dim a As String = "bah" Dim b As String = "bah2" Dim c As String = a & b Dim d As String = String.Concat(a, b)
string a = "bah"; string b = "bah2"; string c = a + b; string d = string.Concat(a, b);
Like I said, doesn't really matter .. but sometimes I use one, and other times I use the other. Is there a recommended one? Should I use the concatenation operator (+/&) for small, known strings and Concat method when
I suggest to use the '&' operator in the examples described above. This
will enable the compiler to concatenate string literals at compile time in
some cases such as '"Bla" & ControlChars.NewLine & "Goo"'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Mythran <ki********@hotmail.comREMOVETRAIL> wrote: Out of curiosity, only, which is recommended for SHORT concatenation...or concatenating two or three strings that are relatively small in size?
Dim a As String = "bah" Dim b As String = "bah2" Dim c As String = a & b Dim d As String = String.Concat(a, b)
string a = "bah"; string b = "bah2"; string c = a + b; string d = string.Concat(a, b);
Like I said, doesn't really matter .. but sometimes I use one, and other times I use the other. Is there a recommended one? Should I use the concatenation operator (+/&) for small, known strings and Concat method when the size/number of strings is unknown?
They compile to the same code - the compiler uses String.Concat internally. However, I believe that using the operator is usually more readable than using string.Concat explicitly.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Ok, thanks Jon.
Mythran This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Davis |
last post by:
I'd like to overload 'comma' to define a concatenation operator for
integer-like classes. I've got some first ideas, but I'd appreciate a
sanity check. The concatenation operator needs to so...
|
by: Kevin C |
last post by:
Quick Question:
StringBuilder is obviously more efficient dealing with string concatenations
than the old '+=' method... however, in dealing with relatively large string
concatenations (ie,...
|
by: Larry Menard |
last post by:
Is it not valid to use concatenation in a WHERE ... LIKE clause?
SELECT iam0.g_itemId
FROM g2_ItemAttributesMap AS iam0,
g2_ItemAttributesMap AS iam1
WHERE iam1.g_parentSequence LIKE...
|
by: michael.martin |
last post by:
Hi,
I am wondering if something like this is possible?
#define COLON ":"
#define PERIOD "."
#define WORD "word"
#define WORD_COLON WORD+COLON
|
by: GM |
last post by:
I am building the text for a resume section label in databinding with 20 or
so data columns using a series of 20 or so code snippits like the following:
If e.Item.DataItem("EmployerDisplay") And...
|
by: Dominique Vandensteen |
last post by:
after the very small & vs string.format discussion I did some speed tests...
loop of 1.000.000 concatenations of 5 public string variables in a class
gave following results:
result = a & b...
|
by: Mythran |
last post by:
Out of curiosity, only, which is recommended for SHORT concatenation...or
concatenating two or three strings that are relatively small in size?
Dim a As String = "bah"
Dim b As String = "bah2"...
|
by: Leonel Gayard |
last post by:
Hi all,
I had to write a small script, and I did it in python instead of
shell-script. My script takes some arguments from the command line,
like this.
import sys
args = sys.argv
if args ==...
|
by: Larry Hastings |
last post by:
This is such a long posting that I've broken it out into sections.
Note that while developing this patch I discovered a Subtle Bug
in CPython, which I have discussed in its own section below.
...
|
by: Edwin Smith |
last post by:
Hello:
I have a problem building a file command line argument from 2 cells in a
table with the following code.
string filePath =...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
|
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...
| |