|
PIEBALDconsult wrote: I'm also not sure what you mean by the title;
Array.Sort(myKeys, myValues, 1, 3);
won't "Sort by the first 3 characters", it sorts the second through fourth items.
Exactly
Thats the real horror, how he gets there is a horror too!
All this has been reduced to 2 lines of code getting data straight from the DB.
|
|
|
|
|
|
This enhances readability.
Greetings from Germany
|
|
|
|
|
leppie wrote: /// /// This method can be customized to return a list of data from any source, e.g database, xml file, object, etc. /// /// <param name="tmpDropDownLists" />Object instance of DropDownLists class. /// <returns>ItemCollection<string> public Collection<listitem> GetTitles(DropDownLists tmpDropDownLists) { //Currently the data is hardcoded, but can also be queried from a database. tmpDropDownLists.myList = new Collection<listitem>(); ListItem li = new ListItem(); li.Value = "1"; li.Text = "Mr."; tmpDropDownLists.myList.Add(li); li = new ListItem(); li.Value = "2"; li.Text = "Mrs."; tmpDropDownLists.myList.Add(li); li = new ListItem(); li.Value = "3"; li.Text = "Me."; tmpDropDownLists.myList.Add(li); li = new ListItem(); li.Value = "4"; li.Text = "Dr."; tmpDropDownLists.myList.Add(li); li = new ListItem(); li.Value = "5"; li.Text = "Prof."; tmpDropDownLists.myList.Add(li);
Oh, if only there existed some technology where you could add items from some source of data. That would be sure to catch on.
|
|
|
|
|
Only if you publish documentation... perhaps on a website.
|
|
|
|
|
A team member wrote this peace of code and I still don't know what she wanted with:
string _attempt = "3";
if( _attempt.ToUpper() == 3 )
OMG, sometimes I ask myself: Will not be better if I was pastryman?
-+--+--+--+--+--+--+-+-+-+
Carlos Zani - SP - Brazil
Powered by Microsof.Net
|
|
|
|
|
I wonder if you are using the same guy as we did!
|
|
|
|
|
This kind of person is in anywhere.
-+--+--+--+--+--+--+-+-+-+
Carlos Zani - SP - Brazil
Powered by Microsof.Net
|
|
|
|
|
See my 'little' horror I just posted.
|
|
|
|
|
Zani Jnior wrote: sometimes I ask myself: Will not be better if I was pastryman?
I often ask myself the very same thing.
We have a running joke at work : there are career opportunities at Taco Bell.
|
|
|
|
|
I just realized I use stuff like that all the time.
Well, for testing anyway.
Especially when I'm not sure what the check will be later.
For example I first write the code between the parenthesis and add the check at a later time, but in the mean time, I can't leave it empty because that makes debugging the code in the parenthesis harder.
Maybe the team member wasn't done testing or forgot he wasn't done.
|
|
|
|
|
Zani Jnior wrote: I still don't know what she wanted with
Beats me with what she was trying to accomplish
"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
|
|
|
|
|
Today I had to write something I consider a horror. It's very much like some similarly bad code that's been exposed here, but no other solution came immediately to mind... and it works.
Without going into detail, I have a form that dynamically creates its controls according to an XML document.
So, if the document specifies "System.DateTime" a DateTimePicker will be instantiated and added to the form.
I also decided to add the ability to control the format via the XML, by setting the CustomFormat property.
All is well and good.
Today I was writing one of these XML documents and needed a DateTime with format "yyyy-MM-dd", simple enough, works great.
Until I realized that I also needed to truncate the DateTime (zero-out the time-of-day part in this case).
Truncating a DateTime is no big deal; I even wrote a (poorly-received) article[^] on it.
But that solution won't work well in this case; I wanted a way to truncate based on the provided format.
After a little thought I had the solution, but it feels so dirty:
mydate = System.DateTime.ParseExact ( mydate.ToString ( format ) , format , null ) ;
I haven't tested it extensively; I'm afraid of what I might find.
|
|
|
|
|
PIEBALDconsult wrote: Until I realized that I also needed to truncate the DateTime (zero-out the time-of-day part in this case).
Maybe I misunderstood you, but couldn't you just use mydate.Date ?
Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
|
|
|
|
|
I was just going to say the same, you beat me by 5 minutes
|
|
|
|
|
No, because I'm provided the format at runtime -- read from an XML file.
The format could be any valid format for a DateTime.
|
|
|
|
|
I did the same.
Something along the lines of:
if (bool.TryParse(someString, out checkBool))
{
someProp1 = checkBool
someString = someProp1.ToString()
}
if (DateTime.TryParse(someString, out checkDate))
{
someProp2 = checkBool
someString = DateTime.Parse(someProp2.ToString()).ToString()
}
It's part of a dynamic Property Grid. Since I couldn't find any type checking for Property Grids, I had to create my own.
And without the above code, if you entered stuff like "trUE" it would remain like that.
With the above code, the user entries are formatted and dates always have the same format as well.
|
|
|
|
|
You can do math on the date to zero-out the time, and then parse it out...
DateTime dt = DateTime.Now;
dt = dt.Subtract(new TimeSpan(0,dt.Hour,dt.Minute,dt.Second,dt.Millisecond));
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Yes, but that doesn't help in this case either.
|
|
|
|
|
This is from the documentation of HashSet<T>.Contains
private static bool isEven(int i)
{
return ((i % 2) == 1);
}
|
|
|
|
|
Indeed (and program output confirms [^])!
And also Visual Basic sample is consistently wrong.
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
|
|
|
|
|
I have now warned all unsuspecting prey. I wonder how many times that CodeDom definition is being used throughout the documentation?
|
|
|
|
|
No wonder why we are getting so many crappy programmers....
Yusuf
|
|
|
|
|
Actually not. For a beginner something like this is not easy to spot. Once they do, they will have learned that you may never go on assumptions and always must check even the simplest things to make certain that they work as they should.
Crappy programmers are those who are totally resistant to learning from their mistakes.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
I think you did not notice the joke icon, oh well.....
Yusuf
|
|
|
|