simple string parsing questions

Feels like homework, but I was in a good mood.

22:28 [ Flav_] then you can do something like: int foo; if
(int.TryParse(textbox.Text, out foo)) { … do something with
the int foo … }
22:29 [ Flav_] int.TryParse looks at the string you pass in, and if it can
parse it as an int, sets the out parameter to the parsed value
and returns true. If it can’t, it returns false
22:30 [ Maxtors] YES! thanks man iv been looking for that for ages… 😛
22:30 [ Maxtors] lol
22:30 [ Flav_] it wasn’t in VS 2003 and earlier – a nice addition to .NET 2.0
22:31 [ Maxtors] hehe:P
22:31 [ Flav_] IIRC double had it back then, but not int
22:31 [ Maxtors] but what if the input == a double value
22:32 [ Flav_] it depends on what you want to do – since “17” can parse as both
an int and a double, you could try one then the other
22:32 [ Flav_] the easier route may be to just parse it as a double regardless
22:33 [ Flav_] then you can do something like: double foo; if
(double.TryParse(textbox.Text, out foo)) { … do something with
the double foo … }
22:33 [ Maxtors] ok… makes sence
22:33 [ Flav_] i guess it depends on how you want to treat them differently
22:33 [ Maxtors] but why foo… i’ve heard it before… is it just a common
thing or a real syntax
22:33 [ Flav_] just common variable name in examples
22:34 [ Flav_] it can be called anything
22:34 [ Maxtors] ok
22:34 [ Flav_] double parsedDouble; if (double.TryParse(textbox.Text, out
parsedDouble)) { … do something with the double parsedDouble
… }
22:35 [ Maxtors] so what is does is that it TRYs to parse it as a double and if
it is sucsessful the do the thing between the {…}
22:35 [ Flav_] yes
22:36 [ Maxtors] ok…
22:40 [ Maxtors] in VB 6.0 you could just write len(text1.text)… to count
the characters can you do that in C#
22:40 [ Flav_] text1.Text.Length
22:40 [ Maxtors] also how can i delete the 1st character in a string then make
it a double…
22:40 [ Flav_] every string has a .Length property that will give you the
number of characters in the string
22:40 [ Maxtors] wait ill give you an example
22:40 [ Flav_] delete the first character is: someString =
someString.Substring(1);
22:41 [ Flav_] if you know it’s a double for sure already, you could then
double someDouble = double.Parse(someString);
22:41 [ Flav_] otherwise, do the same double parsedDouble; if
(double.TryParse(someString, out parsedDouble)) { … }
22:42 [ Maxtors] my label text is “$100″… then i whant to add $10 to that…
22:42 [ Flav_] textbox.Text = “$” + int.Parse(textbox.Text.Substring(1));
22:43 [ Flav_] whoops
22:43 [ Flav_] textbox.Text = “$” + (int.Parse(textbox.Text.Substring(1)) + 10);
22:43 [ Flav_] forgot to add the 10

DirectX coding from C# or VB (any .NET language) – Managed DirectX

16:42 [ daniella`] does C# support DirectX?
16:43 [ skinkflex] yes
16:43 [ skinkflex] dont know anything of it, but i know you can code directx
with .net
18:22 [ Flav_] skinkflex: it’s called “managed directx” – that’s the search
term that will get you the right pages
18:23 [ skinkflex] Flav_: ahh, thats it
18:23 [ Flav_] the .NET 2.0 versions are in beta still

It’s in the normal DirectX SDK – check it out at:

http://msdn.microsoft.com/directx/

SQL Server 2005's Snapshot Isolation Level

If you’ve used Oracle (or listened to the pitch) much, you’ve likely heard the mantra “readers don’t block writers, writers don’t block readers”. This has been true for Oracle for a very long time. It’s implemented with their undo log (also used for rollbacks). To get an idea of how it’s implemented, check out this article on what a update costs in Oracle.

In SQL Server 2000, queries (select statements) took a shared lock on the relevant rows (we’ll ignore lock escalation for now), and updates took exclusive locks. This makes them less overhead, but more contentious (readers blocked writers, writers blocked readers – writers will always block writers, of course, and readers never block readers)

While that’s still the default situation for SQL Server 2005, I’m happy to see that there’s a new “Snapshot” isolation level in 2005 that gives you the the choice to have this “readers don’t block writers and writers don’t block readers” effect. Similar to the undo log, the older versions of the data are kept around, but in the SQL Server 2005 case, this older data is kept around in the tempdb. This has some advantages in terms of easier maintenance, but it can be considered a similar mechanism.

What’s great is that the admin now has a choice. Oracle’s never given you the choice (which is fine, it’s how they chose their architecture), but now SQL Server gives you that choice. In many cases (lots of updates, long-running transactions, etc.), this will be an extremely valuable feature as the previous choice was usually to NOLOCK the long-running queries so they wouldn’t take the shared lock and block writers.

If you’re interested, you should definitely check out this article on the snapshot isolation level in sql server 2005.

intro to the new team system profiler

21:47 [ Flav] yeah, the clr profiler is good for showing allocations of different types. I’ve been using the VS 2005 Team Suite RC, so I’ve gotten spoiled on the new profiler 🙂
21:48 [ djperegrine] VS 2005 has a profiler ?
21:49 [ Flav] in team system
21:49 [ Flav] there’s a nice intro blog post @ http://blogs.msdn.com/ianhu/archive/2005/02/07/368779.aspx
21:51 [ Flav] it doesn’t help much for 1.1 apps, though – see the forum post @ http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=94226
21:52 [ Flav] the “info hub” blog post is @ http://blogs.msdn.com/ianhu/archive/2005/06/09/427327.aspx

how can i tell where all the memory is in my managed app?

21:35 [ jp-] is there a way in vs.net 2003 to see how much memory objects are consuming?
21:39 [ jp-] well i’m trying to compress DIB’s using Image.Save(stream, some_image_format_with_compression) and i’d like to come up with a way to see what’s using all the memory
21:40 [ Flav] the CLR Profiler is good for checking memory allocation
21:40 [ Flav] http://www.microsoft.com/downloads/details.aspx?FamilyId=86CE6052-D7F4-4AEB-9B7A-94635BEEBDDA&displaylang=en
21:41 [ Flav] if you’re using Visual Studio Team System, you could use the new built-in profiler – it’s very slick.

structs, oh yes, can definitely contain methods

22:57 [ Kog] although… a struct doesn’t have methods does it?
22:59 [ Flav] Kog: DateTime is a struct.. lots of methods on it 🙂
23:00 [ Kog] Flav, doing too much C has broken the word struct in my mind

Yes, they’re allocated on the stack, but structs can still do lots and lots of useful things.

The biggest thing to keep in mind (IMHO) when creating your own struct types (*not* in simply using them) is to make sure that you thing of structs as value types – they should not change their value once they’re constructed. They should, most definitely, be immutable.

Here’s a relevant post I like to nickname: Mutable structs considered harmful.

more irc answers

question on the Enterprise Library for June 2005

23:19 [ [Cr]] Does anyone know where to download the Enterprise Library June 2005? I dug around on the net for an hour last night
and couldn’t find an actual download site…
23:39 [ Flav] http://practices.gotdotnet.com/projects/entlib
23:39 [ Flav] which points to the June 2005 info @
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/entlib.asp
23:39 [ Flav] which points to the Enterprise Library, June 2005 download @
http://www.microsoft.com/downloads/details.aspx?FamilyId=A7D2A109-660E-444E-945A-6B32AF1581B3&displaylang=en