How to add a single item to an array
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Or:
var ccList = Enumerable.Range(0,1);
var objects = ccList.Select(x=> (object)cc);
foo.Items = objects.ToArray();:laugh:
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
That code will work, but, like my signature says, that doesn't mean it is a good way to do it. :rolleyes:
Just because the code works, it doesn't mean that it is good code.
BillW33 wrote:
That code will work, but, like my signature says, that doesn't mean it is a good way to do it. :rolleyes:
And I suppose this is exactly why he is posting it in this forum ;P :-D
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
BillW33 wrote:
That code will work, but, like my signature says, that doesn't mean it is a good way to do it. :rolleyes:
And I suppose this is exactly why he is posting it in this forum ;P :-D
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
Nelek wrote:
And I suppose this is exactly why he is posting it in this forum
Darn, I'm so predictable. ;)
Latest Article - Code Review - What You Can Learn From a Single Line of Code Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
Nelek wrote:
And I suppose this is exactly why he is posting it in this forum
Darn, I'm so predictable. ;)
Latest Article - Code Review - What You Can Learn From a Single Line of Code Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
great minds think alike :rolleyes: :rolleyes:
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Thanks for sharing this great snippet of codez, bro! It will help me speed up my development work. :-D
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
How come nobody came up with the one line solution :rolleyes: ?
foo.items = new List() { cc }.ToArray();
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Quite. ToArray and ToList are code smells. As are pretty must all Toxxx methods. (ToString can be OK, but it's often misused as well.)
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
Quite. ToArray and ToList are code smells. As are pretty must all Toxxx methods. (ToString can be OK, but it's often misused as well.)
-
Quite. ToArray and ToList are code smells. As are pretty must all Toxxx methods. (ToString can be OK, but it's often misused as well.)
If the only code being consumed is your code then I agree completely but
ToArray
can be useful when dealing with an external library that doesn't acceptList
. Forcing your own code to use a plain array simply to avoid aToArray
call could be much, much worse depending on how your code uses that array. I'd lob them in with what you said aboutToString
. It can be useful but is often misused. -
How come nobody came up with the one line solution :rolleyes: ?
foo.items = new List() { cc }.ToArray();
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Never heard of it until you asked - so I had to look at wikipedia.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Never heard of it until you asked - so I had to look at wikipedia.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
As the Wikipedia article says: "In nearly all versions of APL, it is theoretically possible to express any computable function in one expression, that is, in one line of code" - the one-liner Game of Life is an excellent example. I learned APL as early as 1975-76, on one of the worlds earliest "PCs", the IBM 5100 - APL was almost exclusively an IBM thing then - and it was a well known joke that IBM was working on writing the entire OS360 (the first operating system for the 360/370 mainframe series) in a single line of APL :-) There are still elements of APL that I miss, in particular the "workspace" concept: You do your stuff in a sandpit where you throw in functions, variables and whatever stuff, and throw them out when no longer needed - while the "program" (workspace) running. On the 5100, you could save the entire workspace on disk in its current state, or you could declare selected variables as persistent. There were file system operations, but you rarely needed it. There have been languages with similar concepts (I believe Smalltalk comes close), but mainline programming 40 years later still are based on concepts that could be compared to "Of course you have to tell how much space to reserve for a file before starting to use it" (that's essentially how IBMs mainframe file systems were at the time). APL was so much more flexible and dynamic... I'm getting carried away. Maybe I tonight should curl up in my recliner in front of my fireplace with the old APL book, memorizing what the world was like when I was a youngster...
-
As the Wikipedia article says: "In nearly all versions of APL, it is theoretically possible to express any computable function in one expression, that is, in one line of code" - the one-liner Game of Life is an excellent example. I learned APL as early as 1975-76, on one of the worlds earliest "PCs", the IBM 5100 - APL was almost exclusively an IBM thing then - and it was a well known joke that IBM was working on writing the entire OS360 (the first operating system for the 360/370 mainframe series) in a single line of APL :-) There are still elements of APL that I miss, in particular the "workspace" concept: You do your stuff in a sandpit where you throw in functions, variables and whatever stuff, and throw them out when no longer needed - while the "program" (workspace) running. On the 5100, you could save the entire workspace on disk in its current state, or you could declare selected variables as persistent. There were file system operations, but you rarely needed it. There have been languages with similar concepts (I believe Smalltalk comes close), but mainline programming 40 years later still are based on concepts that could be compared to "Of course you have to tell how much space to reserve for a file before starting to use it" (that's essentially how IBMs mainframe file systems were at the time). APL was so much more flexible and dynamic... I'm getting carried away. Maybe I tonight should curl up in my recliner in front of my fireplace with the old APL book, memorizing what the world was like when I was a youngster...
370 is one of those numbers where, if you cube the digits and add the results, it comes out to the original number. 3 x 3 x 3 = 27 7 x 7 x 7 = 343 0 x 0 x 0 = 0 27 + 343 + 0 = 370 (I worked for I've Been Moved from 1979-1987) :)
Cheers, Mike Fidler "I intend to live forever - so far, so good." Steven Wright "I almost had a psychic girlfriend but she left me before we met." Also Steven Wright "I'm addicted to placebos. I could quit, but it wouldn't matter." Steven Wright yet again.
-
could be worse ...
string[] oldarray = { "A", "B", "C" };
string newitem = "D";
oldarray = (String.Join(",", oldarray) + "," + newitem).Split(',');Consult your mental health professional immediately! ;)
Cheers, Mike Fidler "I intend to live forever - so far, so good." Steven Wright "I almost had a psychic girlfriend but she left me before we met." Also Steven Wright "I'm addicted to placebos. I could quit, but it wouldn't matter." Steven Wright yet again.
-
370 is one of those numbers where, if you cube the digits and add the results, it comes out to the original number. 3 x 3 x 3 = 27 7 x 7 x 7 = 343 0 x 0 x 0 = 0 27 + 343 + 0 = 370 (I worked for I've Been Moved from 1979-1987) :)
Cheers, Mike Fidler "I intend to live forever - so far, so good." Steven Wright "I almost had a psychic girlfriend but she left me before we met." Also Steven Wright "I'm addicted to placebos. I could quit, but it wouldn't matter." Steven Wright yet again.
MikeTheFid wrote:
(I worked for I've Been Moved from 1979-1987)
So maybe you can confirm (or deny) what I've been told: An icon used in the 360 series marketing was a full circle, with one vertical radius drawn, like in a tradional "on/off" toggle button. Then I have heard said that the icon chosen for the 370 series was a bigger circle :-) People telling this story illustrate the new icon: A double circle, not consentric but touching where the radius crosses the rim. I can't remember ever seing this symbol in officiall IBM documentation, but maybe it was before I got into computing. (And, my only experience with IBM mainframes is for a single student project, on a remote machine I never saw.) Maybe this was an internal joke within IBM. Or maybe outside IBM. As we say where I live: If it isn't the truth, it sure is a great lie! ... I think it is so great that I sort of wish that it is true :-)
-
List ccList = new List();
ccList.Add(cc);
foo.Items = ccList.ToArray();- Create a list.
- Add the item to the list.
- Convert the list to an array.
:sigh:
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802