|
True.
|
|
|
|
|
|
|
8 years and 9 months in the making. Can't wait for the next installment.
Peter Wasser
"The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell
|
|
|
|
|
He found his lost password in the cab so he was thanking.
___ ___ ___
|__ |_| |\ | | |_| \ /
__| | | | \| |__| | | /
|
|
|
|
|
Curse you, C#!
cheers
Chris Maunder
|
|
|
|
|
We (C# devs who've programmed in C/C++) have all felt that at some time or other.
But think of all the pointer arithmetic you've been able to forget about and that should make you happy...right?
|
|
|
|
|
and if you fancy doing some pointer arithmetic in C# then string[i] = 'x' is possible - but crazy
|
|
|
|
|
StringBuilder will do that.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
TheGreatAndPowerfulOz wrote: StringBuilder will do that.
Great catch!
StringBuilder s = new StringBuilder("tool");
s[0] = 'c';
Console.WriteLine(s.ToString());
|
|
|
|
|
It's too bad you can't do it in one line of code though...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
StringBuilder is not string.
cheers
Chris Maunder
|
|
|
|
|
Picky, picky.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Are you sure?
StringBuilder
|
|
|
|
|
If that were possible in C#, wouldn't that "weaken" the (what I perceive as) intention of the language designers to enforce string immutability ?
Sure, you can do a work-around using Extension Methods. Visual Basic allows you pass the 'this parameter of an Extension Method by reference, while C# does not, so something like this will do:
public static string SetChar(this string str, int ndx, char ch)
{
if(ndx >= str.Length) throw new ArgumentOutOfRangeException();
charAry = str.ToCharArray();
charAry.SetValue(ch,ndx);
return new string(charAry);
} I used a 'CharArray here simply because TheGreatAndPowerfulOz already mentioned using StringBuilder.
However, you could write an Extension Method on 'Char, and pass the string by reference, but that syntax would look kind of weird: string somesubstitution = 'x'.SetCharInto(ref mystringVar, 3);
Gosh, I wish I CodeProject had a Forum where a lot of people really discussed C# language issues ! In case that statement is not clear to some of you: I am indirectly lamenting the fact that the C# language forum is now not what it was many years ago in terms of real interchanges about language features, often, imho, full of questions that should have been posted on the QA forums.
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Shouldn't the sanity check be this:
if(ndx >= str.Length-1) throw new ArgumentOutOfRangeException();
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Hi John, nope the test I show allows you to change the last character, but the test you show would only let you change up-to the character before the last character.
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
You're right, of course.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
It's so rare that I'm "right" that I can make a meal out of even a crumb ... like this.
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
You can write unsafe code that will allow you to access individual characters.
BillWoodruff wrote: C# language forum is now not what it was many years ago in terms of real interchanges about language features, often, imho, full of questions that should have been posted on the QA forums.
So how do we fix that?
A couple of options
1. We allow members to move questions from the forums to QA.
2. We combine all forums into one, and call it "Programming Discussions". Not for questions, but for discussions. The Lounge for Programers.
3. ?
cheers
Chris Maunder
|
|
|
|
|
Hi Chris, I wish I had a really specific constructive suggestion to make ! As I perceive it, it is not the tao of CP to have moderated forums, and I wonder if you'd be willing to move in such a direction, if the membership would accept that.
I think every MVP and Mentor should be willing to do some "jury duty" for some period of time ... if you enable these folks to move questions from the C# language forum to QA.
Then there's the question: is there really an "appetite" for discussion of language issues and quirks, and work-arounds, and such ? Is it the case of "build it and they will come" ?
I've long felt that valuable programming content ... that would be useful to members in the future ... appears here on the Lounge, and then kind of gets submerged in the spate of the usual frivolities.
But, who's going to somehow curate/tag that content, or copy it to a place where it persists and is indexed in a valuable way ?
But, just because I see a few pimples on the angels, does not mean I do not see CP, as it is now, as paradise
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Switch to VB.NET and she'll be right:
Dim s As String = "Cool"
Mid$(s, 1) = "F"
Console.WriteLine(s)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ok, this is a bit of rant.
I'm building a UWP (Universal Windows Platform) app -- XAML / C#.
I've developed software all the way back to Win3.1 using Visual Studio 1.x and the MFC.
Now, I've just been forced to create a new UserControl in XAML because the functionality hasn't been wrapped up for what I want (NumericUpDown control).
But for hours I could not figure out why the button wouldn't render itself properly -- the text (content) on the button will not display.
Find out there's way more you have to do to get it working, simply because this stuff doesn't quite work. Great.
Took About 1 Day to Convert Winform to Android App
But, there's more to this. I wrote this app as a Winform app and then converted it in a day or so to an Android app. I re-wrote the entire Winform app natively using Android Studio.
Think about that...
The Point
I've been developing on Windows Platform for 25 years but it is easier for me as a developer to convert it to an Android app than it is to convert it to a Universal Windows App.
Dear Microsoft:
You are failing on both of your (previous) strengths:
1. Desktop OS
2. Development tools
It is too bad because during XP through Windows 7, things weren't entirely terrible.
I suppose you will just be a fading memory soon anyways.
Sincerely,
Software Developers Everywhere
modified 18-Sep-16 18:27pm.
|
|
|
|
|
Reminds me of the Soviet era, when it was cheaper and faster to export products out of Leningrad (St Petersburg nowadays) then import them to Vladivostok rather than to have to ship them inside the Soviet Union.
Anyway, when all the exotic artifacts (re Windows development) pile up during the years, of course it will be difficult. You have to remember all the arcane details, for example that 32-bit system .dlls are stored in C:\Windows\syswow64 and 64-bit system .dlls are stored in C:\Windows\system32. If that makes sense to you then you will be an exemplary Windows developer.
|
|
|
|
|
|