|
by the lower intestinal tract.
Then how its by value???
Once its passed, you wont get the original.......
|
|
|
|
|
I'm cracking up I'm shedding tears the people I work with are looking at me like I'm crazy.
|
|
|
|
|
What's the point of your post?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
After the function call its printing 30, That is the matter
|
|
|
|
|
Sherin Iranimose wrote: After the function call its printing 30
So, that's the horror part? *look at forum title* *Disappointed*
|
|
|
|
|
For some reason, I sense you are asking a programming question. That is a big NO in this particular forum.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
this looks like a programming question.
On top of this forum it's said in big bold red letters:
Do not post programming questions in this forum...
If it is a question, move it to the C# forum. Btw: objects (including strings) are passed by reference to my knowledge. You should be able to find this on msdn somewhere.
|
|
|
|
|
V. wrote: objects (including strings) are passed by reference to my knowledge
Nope. All parameters are passed by value. you should use the ref keyword to pass a parameter by reference. BTW: passing by value an object implies that called function can actually change object's internal state.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
This is incorrect. Classes are passed by reference, Structs are passed by value.
CPallini wrote: BTW: passing by value an object implies that called function can actually change object's internal state.
[Smile]
This means nothing of the sort. Passing by value simply means that an object in a method is distinct from the original object and any changes made to that object are not reflected in the original.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
You are wrong. Whenever you pass an object, a reference to the object's instance is passed by value.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
This appears to be C# code. Classes are passed by reference by design.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I guess it gets passed by reference because it is C#.
In C++ by value.
Greetings from Germany
|
|
|
|
|
Value-type objects such as structs are created on the stack, while reference-type objects such as classes are created on the heap.
So it is actually a PASS - BY - REFERENCE
Both types of objects are destroyed automatically, but objects based on value types are destroyed when they go out of scope, whereas objects based on reference types are destroyed at an unspecified time after the last reference to them is removed.
Happy Coding!
Mitendra
|
|
|
|
|
The object is passed by value, but the what is actually passed since it is a reference object is a pointer to the object. So, the "value" that is actually passed is the pointer not the object and therefore any changes made through the pointer change the original object. What you can't change is the pointer itself. That is the "value".
|
|
|
|
|
You are right Jon. I see your point.
|
|
|
|
|
I found this little gem in an app I worked on recently.
switch (strValue.GetLength())
{
case 1:
{
strValue = "00000" + strValue;
break;
}
case 2:
{
strValue = "0000" + strValue;
break;
}
case 3:
{
strValue = "000" + strValue;
break;
}
case 4:
{
strValue = "00" + strValue;
break;
}
case 5:
{
strValue = "0" + strValue;
break;
}
case 6:
{
break;
}
}
And yes, the code I replaced with comments is the same for all 6 cases.
|
|
|
|
|
Hey, those zeroes are valuable, you can't just go throwing them around willy-nilly!!
Sure, it could have been done with a single append then take the right 6 chars, but how many 0's would have been needlessly lost? Consigned to the bit-bucket of history, before their time... Show some mercy, man!!
--------------------------------------------------------
Knowledge is knowing that the tomato is a fruit.
Wisdom is not putting it in fruit salad!!
|
|
|
|
|
But... they're insignificant.
|
|
|
|
|
Nice. Did you fire up the blame engine (source control) and find the culprit?
Steve
|
|
|
|
|
It does not work that well with outsource contractors! (I have seen similar code from those).
|
|
|
|
|
That was, in fact, my first reaction. I found the culprit, and he still works here.
|
|
|
|
|
Ick - I've seen way too much of this type of thing in code over the last 3 decades. I've come to calling this style of programming "brute force" programming.
So, whoever wrote this loses lots of points for elegance (or the lack thereof), but they do get some points in my book for style (use of braces, indentation, etc). No default case however...
|
|
|
|
|
This is indeed not good, the switch statement isn't flexible at all.
One should master the power off recursion
CString Pad(CString strValue, int iPadSize)
{
if(strValue.GetLength() >= iPadSize)
{
return strValue;
}
else
{
strValue = Pad(CString("0") + strValue, iPadSize);
};
return strValue;
}
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
He didn't simply append one zero in each case block and then fall through?
Did he ensure the strValue was trimmed?
I'm curious what you replaced it with.
Of course, in .net, providing the proper format string to int.ToString() will do it in one swell foop.
|
|
|
|
|
I believe it would be int.ToString(some_string, "000000"); . Of course, I haven't programmed for a while, so I might be wrong.
So the creationist says: Everything must have a designer. God designed everything.
I say: Why is God the only exception? Why not make the "designs" (like man) exceptions and make God a creation of man?
|
|
|
|