<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: dict.GetAt error return code? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040012#M77321</link>
    <description>Thanks, Tony - I might be able to use this in a few other areas to clean up some machete-code I inherited.</description>
    <pubDate>Fri, 10 Aug 2007 15:12:17 GMT</pubDate>
    <dc:creator>dgorsman</dc:creator>
    <dc:date>2007-08-10T15:12:17Z</dc:date>
    <item>
      <title>dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040004#M77313</link>
      <description>Can we test for a key in a dictionary without using the IDictionary&lt;BR /&gt;
Enumerator and testing the whole dictionary. I was hoping for a retun&lt;BR /&gt;
code similar to ARX eKeyNotFound when using dict.GetAt but this&lt;BR /&gt;
just throws a system error when not found.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Wed, 08 Aug 2007 18:02:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040004#M77313</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-08T18:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040005#M77314</link>
      <description>Here's what I'm using - actually very quick.&lt;BR /&gt;
[code]&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
{&lt;BR /&gt;
&lt;BR /&gt;
    foreach (DictionaryEntry de in dbDict)&lt;BR /&gt;
    {&lt;BR /&gt;
&lt;BR /&gt;
        if (de.Key.ToString() == dictKey)&lt;BR /&gt;
            return true;&lt;BR /&gt;
    }&lt;BR /&gt;
&lt;BR /&gt;
    return false;&lt;BR /&gt;
}&lt;BR /&gt;
[/code]&lt;BR /&gt;
"Paul Richardson" &lt;P&gt; wrote in message &lt;BR /&gt;
news:5683828@discussion.autodesk.com...&lt;BR /&gt;
Can we test for a key in a dictionary without using the IDictionary&lt;BR /&gt;
Enumerator and testing the whole dictionary. I was hoping for a retun&lt;BR /&gt;
code similar to ARX eKeyNotFound when using dict.GetAt but this&lt;BR /&gt;
just throws a system error when not found.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2007 18:22:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040005#M77314</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-08T18:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040006#M77315</link>
      <description>How about this code&lt;BR /&gt;
&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
        {&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                ObjectId id = dbDict.GetAt(dictKey);&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch&lt;BR /&gt;
            {&lt;BR /&gt;
                return false;&lt;BR /&gt;
            }&lt;BR /&gt;
        }</description>
      <pubDate>Thu, 09 Aug 2007 07:14:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040006#M77315</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-09T07:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040007#M77316</link>
      <description>I try to keep my trys for the unexpected but since it's an IDict it's&lt;BR /&gt;
either this or the loop. Thanks.&lt;BR /&gt;
&lt;HAR&gt; wrote in message news:5684537@discussion.autodesk.com...&lt;BR /&gt;
How about this code&lt;BR /&gt;
&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
        {&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                ObjectId id = dbDict.GetAt(dictKey);&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch&lt;BR /&gt;
            {&lt;BR /&gt;
                return false;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;/HAR&gt;</description>
      <pubDate>Thu, 09 Aug 2007 11:53:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040007#M77316</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-09T11:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040008#M77317</link>
      <description>Paul - What's wrong with the Contains() method ?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;P&gt; wrote in message news:5684696@discussion.autodesk.com...&lt;BR /&gt;
I try to keep my trys for the unexpected but since it's an IDict it's&lt;BR /&gt;
either this or the loop. Thanks.&lt;BR /&gt;
&lt;HAR&gt; wrote in message news:5684537@discussion.autodesk.com...&lt;BR /&gt;
How about this code&lt;BR /&gt;
&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
        {&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                ObjectId id = dbDict.GetAt(dictKey);&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch&lt;BR /&gt;
            {&lt;BR /&gt;
                return false;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;/HAR&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2007 21:09:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040008#M77317</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-09T21:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040009#M77318</link>
      <description>Nothing wrong with Contains() it's the coder...:) Thanks!&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message &lt;BR /&gt;
news:5685719@discussion.autodesk.com...&lt;BR /&gt;
Paul - What's wrong with the Contains() method ?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;P&gt; wrote in message &lt;BR /&gt;
news:5684696@discussion.autodesk.com...&lt;BR /&gt;
I try to keep my trys for the unexpected but since it's an IDict it's&lt;BR /&gt;
either this or the loop. Thanks.&lt;BR /&gt;
&lt;HAR&gt; wrote in message news:5684537@discussion.autodesk.com...&lt;BR /&gt;
How about this code&lt;BR /&gt;
&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
        {&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                ObjectId id = dbDict.GetAt(dictKey);&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch&lt;BR /&gt;
            {&lt;BR /&gt;
                return false;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;/HAR&gt;&lt;/P&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Thu, 09 Aug 2007 21:22:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040009#M77318</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-09T21:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040010#M77319</link>
      <description>Just a point of clarification.&lt;BR /&gt;
&lt;BR /&gt;
If you are testing to see if a key exists, and&lt;BR /&gt;
if it does, retrieving the value, then don't use&lt;BR /&gt;
Contains() followed by GetAt(), like this:&lt;BR /&gt;
&lt;BR /&gt;
   DBDictionary dict = // ...&lt;BR /&gt;
&lt;BR /&gt;
   if( dict.Contains("mykey") )&lt;BR /&gt;
   {&lt;BR /&gt;
       ObjectId id = dict.GetAt("mykey");&lt;BR /&gt;
       // use id &lt;BR /&gt;
   }&lt;BR /&gt;
&lt;BR /&gt;
The reason this is not the preferred method, is &lt;BR /&gt;
because it requires two lookups, rather than one.&lt;BR /&gt;
&lt;BR /&gt;
Here is how I would do it:&lt;BR /&gt;
&lt;BR /&gt;
   DBDictionary dict = // ........&lt;BR /&gt;
   ObjectId id = ObjectId.Null;&lt;BR /&gt;
   try&lt;BR /&gt;
   {&lt;BR /&gt;
        dict.GetAt("mykey");&lt;BR /&gt;
   }&lt;BR /&gt;
   catch {}&lt;BR /&gt;
 &lt;BR /&gt;
   if( ! id.IsNull )&lt;BR /&gt;
   {&lt;BR /&gt;
        // use id here.&lt;BR /&gt;
   }&lt;BR /&gt;
&lt;BR /&gt;
The reason I would take this approach is because&lt;BR /&gt;
it allows me to get an existing value with only one&lt;BR /&gt;
lookup rather than two (e.g., Contains() does one,&lt;BR /&gt;
and GetAt() does another lookup).&lt;BR /&gt;
&lt;BR /&gt;
Yes, it uses exception handling.&lt;BR /&gt;
&lt;BR /&gt;
Yes, if your dictionary only has a handful of items&lt;BR /&gt;
in it, it'll have no noticeable difference.&lt;BR /&gt;
&lt;BR /&gt;
But, for the purpose of good, efficient coding and &lt;BR /&gt;
scalable performance, in this case, using exception &lt;BR /&gt;
handling allows you to get an existing value from &lt;BR /&gt;
a dictionary with only one lookup, rather than two.&lt;BR /&gt;
&lt;BR /&gt;
So, if someone has been preaching that without &lt;BR /&gt;
condition, you should limit the use of use try/catch &lt;BR /&gt;
to trapping unexpected errors, they're mistaken.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;P&gt; wrote in message news:5685742@discussion.autodesk.com...&lt;BR /&gt;
Nothing wrong with Contains() it's the coder...:) Thanks!&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message &lt;BR /&gt;
news:5685719@discussion.autodesk.com...&lt;BR /&gt;
Paul - What's wrong with the Contains() method ?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;/TONY.TANZILLO&gt;&lt;/P&gt;&lt;P&gt; wrote in message &lt;BR /&gt;
news:5684696@discussion.autodesk.com...&lt;BR /&gt;
I try to keep my trys for the unexpected but since it's an IDict it's&lt;BR /&gt;
either this or the loop. Thanks.&lt;BR /&gt;
&lt;HAR&gt; wrote in message news:5684537@discussion.autodesk.com...&lt;BR /&gt;
How about this code&lt;BR /&gt;
&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
        {&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                ObjectId id = dbDict.GetAt(dictKey);&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch&lt;BR /&gt;
            {&lt;BR /&gt;
                return false;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;/HAR&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2007 02:07:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040010#M77319</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-10T02:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040011#M77320</link>
      <description>Thank you Tony - Nice explanation~&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message &lt;BR /&gt;
news:5685995@discussion.autodesk.com...&lt;BR /&gt;
Just a point of clarification.&lt;BR /&gt;
&lt;BR /&gt;
If you are testing to see if a key exists, and&lt;BR /&gt;
if it does, retrieving the value, then don't use&lt;BR /&gt;
Contains() followed by GetAt(), like this:&lt;BR /&gt;
&lt;BR /&gt;
   DBDictionary dict = // ...&lt;BR /&gt;
&lt;BR /&gt;
   if( dict.Contains("mykey") )&lt;BR /&gt;
   {&lt;BR /&gt;
       ObjectId id = dict.GetAt("mykey");&lt;BR /&gt;
       // use id&lt;BR /&gt;
   }&lt;BR /&gt;
&lt;BR /&gt;
The reason this is not the preferred method, is&lt;BR /&gt;
because it requires two lookups, rather than one.&lt;BR /&gt;
&lt;BR /&gt;
Here is how I would do it:&lt;BR /&gt;
&lt;BR /&gt;
   DBDictionary dict = // ........&lt;BR /&gt;
   ObjectId id = ObjectId.Null;&lt;BR /&gt;
   try&lt;BR /&gt;
   {&lt;BR /&gt;
        dict.GetAt("mykey");&lt;BR /&gt;
   }&lt;BR /&gt;
   catch {}&lt;BR /&gt;
&lt;BR /&gt;
   if( ! id.IsNull )&lt;BR /&gt;
   {&lt;BR /&gt;
        // use id here.&lt;BR /&gt;
   }&lt;BR /&gt;
&lt;BR /&gt;
The reason I would take this approach is because&lt;BR /&gt;
it allows me to get an existing value with only one&lt;BR /&gt;
lookup rather than two (e.g., Contains() does one,&lt;BR /&gt;
and GetAt() does another lookup).&lt;BR /&gt;
&lt;BR /&gt;
Yes, it uses exception handling.&lt;BR /&gt;
&lt;BR /&gt;
Yes, if your dictionary only has a handful of items&lt;BR /&gt;
in it, it'll have no noticeable difference.&lt;BR /&gt;
&lt;BR /&gt;
But, for the purpose of good, efficient coding and&lt;BR /&gt;
scalable performance, in this case, using exception&lt;BR /&gt;
handling allows you to get an existing value from&lt;BR /&gt;
a dictionary with only one lookup, rather than two.&lt;BR /&gt;
&lt;BR /&gt;
So, if someone has been preaching that without&lt;BR /&gt;
condition, you should limit the use of use try/catch&lt;BR /&gt;
to trapping unexpected errors, they're mistaken.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;P&gt; wrote in message &lt;BR /&gt;
news:5685742@discussion.autodesk.com...&lt;BR /&gt;
Nothing wrong with Contains() it's the coder...:) Thanks!&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message&lt;BR /&gt;
news:5685719@discussion.autodesk.com...&lt;BR /&gt;
Paul - What's wrong with the Contains() method ?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;/TONY.TANZILLO&gt;&lt;/P&gt;&lt;P&gt; wrote in message&lt;BR /&gt;
news:5684696@discussion.autodesk.com...&lt;BR /&gt;
I try to keep my trys for the unexpected but since it's an IDict it's&lt;BR /&gt;
either this or the loop. Thanks.&lt;BR /&gt;
&lt;HAR&gt; wrote in message news:5684537@discussion.autodesk.com...&lt;BR /&gt;
How about this code&lt;BR /&gt;
&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
        {&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                ObjectId id = dbDict.GetAt(dictKey);&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch&lt;BR /&gt;
            {&lt;BR /&gt;
                return false;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;/HAR&gt;&lt;/P&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Fri, 10 Aug 2007 03:28:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040011#M77320</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-10T03:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040012#M77321</link>
      <description>Thanks, Tony - I might be able to use this in a few other areas to clean up some machete-code I inherited.</description>
      <pubDate>Fri, 10 Aug 2007 15:12:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040012#M77321</guid>
      <dc:creator>dgorsman</dc:creator>
      <dc:date>2007-08-10T15:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: dict.GetAt error return code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040013#M77322</link>
      <description>&amp;gt;&amp;gt; Here is how I would do it:&lt;BR /&gt;
&lt;BR /&gt;
Oops.  Sorry, that should have been:&lt;BR /&gt;
&lt;BR /&gt;
   DBDictionary dict = // ........&lt;BR /&gt;
   ObjectId id = ObjectId.Null;&lt;BR /&gt;
   try&lt;BR /&gt;
   {&lt;BR /&gt;
        id = dict.GetAt("mykey");&lt;BR /&gt;
   }&lt;BR /&gt;
   catch {}&lt;BR /&gt;
 &lt;BR /&gt;
   if( ! id.IsNull )&lt;BR /&gt;
   {&lt;BR /&gt;
        // use id here.&lt;BR /&gt;
   }&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message news:5685995@discussion.autodesk.com...&lt;BR /&gt;
Just a point of clarification.&lt;BR /&gt;
&lt;BR /&gt;
If you are testing to see if a key exists, and&lt;BR /&gt;
if it does, retrieving the value, then don't use&lt;BR /&gt;
Contains() followed by GetAt(), like this:&lt;BR /&gt;
&lt;BR /&gt;
   DBDictionary dict = // ...&lt;BR /&gt;
&lt;BR /&gt;
   if( dict.Contains("mykey") )&lt;BR /&gt;
   {&lt;BR /&gt;
       ObjectId id = dict.GetAt("mykey");&lt;BR /&gt;
       // use id &lt;BR /&gt;
   }&lt;BR /&gt;
&lt;BR /&gt;
The reason this is not the preferred method, is &lt;BR /&gt;
because it requires two lookups, rather than one.&lt;BR /&gt;
&lt;BR /&gt;
Here is how I would do it:&lt;BR /&gt;
&lt;BR /&gt;
   DBDictionary dict = // ........&lt;BR /&gt;
   ObjectId id = ObjectId.Null;&lt;BR /&gt;
   try&lt;BR /&gt;
   {&lt;BR /&gt;
        dict.GetAt("mykey");&lt;BR /&gt;
   }&lt;BR /&gt;
   catch {}&lt;BR /&gt;
 &lt;BR /&gt;
   if( ! id.IsNull )&lt;BR /&gt;
   {&lt;BR /&gt;
        // use id here.&lt;BR /&gt;
   }&lt;BR /&gt;
&lt;BR /&gt;
The reason I would take this approach is because&lt;BR /&gt;
it allows me to get an existing value with only one&lt;BR /&gt;
lookup rather than two (e.g., Contains() does one,&lt;BR /&gt;
and GetAt() does another lookup).&lt;BR /&gt;
&lt;BR /&gt;
Yes, it uses exception handling.&lt;BR /&gt;
&lt;BR /&gt;
Yes, if your dictionary only has a handful of items&lt;BR /&gt;
in it, it'll have no noticeable difference.&lt;BR /&gt;
&lt;BR /&gt;
But, for the purpose of good, efficient coding and &lt;BR /&gt;
scalable performance, in this case, using exception &lt;BR /&gt;
handling allows you to get an existing value from &lt;BR /&gt;
a dictionary with only one lookup, rather than two.&lt;BR /&gt;
&lt;BR /&gt;
So, if someone has been preaching that without &lt;BR /&gt;
condition, you should limit the use of use try/catch &lt;BR /&gt;
to trapping unexpected errors, they're mistaken.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;P&gt; wrote in message news:5685742@discussion.autodesk.com...&lt;BR /&gt;
Nothing wrong with Contains() it's the coder...:) Thanks!&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message &lt;BR /&gt;
news:5685719@discussion.autodesk.com...&lt;BR /&gt;
Paul - What's wrong with the Contains() method ?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
"Paul Richardson" &lt;/TONY.TANZILLO&gt;&lt;/P&gt;&lt;P&gt; wrote in message &lt;BR /&gt;
news:5684696@discussion.autodesk.com...&lt;BR /&gt;
I try to keep my trys for the unexpected but since it's an IDict it's&lt;BR /&gt;
either this or the loop. Thanks.&lt;BR /&gt;
&lt;HAR&gt; wrote in message news:5684537@discussion.autodesk.com...&lt;BR /&gt;
How about this code&lt;BR /&gt;
&lt;BR /&gt;
static public bool HasKey(DBDictionary dbDict, string dictKey)&lt;BR /&gt;
        {&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                ObjectId id = dbDict.GetAt(dictKey);&lt;BR /&gt;
                return true;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch&lt;BR /&gt;
            {&lt;BR /&gt;
                return false;&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;/HAR&gt;&lt;/P&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Fri, 10 Aug 2007 20:28:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dict-getat-error-return-code/m-p/2040013#M77322</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-08-10T20:28:53Z</dc:date>
    </item>
  </channel>
</rss>

