<?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: First or Default in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826757#M3086</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Brian, just change your test from "IndexOf" to "==" or string.Compare. Currently, you are testing for any layer that contains the string "GISWRKS1.WORKS.ForceMain" which is not what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p.s. As an alternative, you can also include lambdas in most all LINQ extensions if you want to make your statements more concise...[for example Where(x =&amp;gt; x == 1).FirstOrDefault() versus FirstOrDefault(x =&amp;gt; x == 1)]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/8059285/c-sharp-linq-whereexpression-firstordefault-vs-firstordefaultexpression"&gt;https://stackoverflow.com/questions/8059285/c-sharp-linq-whereexpression-firstordefault-vs-firstordefaultexpression&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Jun 2018 17:21:30 GMT</pubDate>
    <dc:creator>CharlesMacleod</dc:creator>
    <dc:date>2018-06-13T17:21:30Z</dc:date>
    <item>
      <title>First or Default</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826756#M3085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When using the following code to find a specific layer in my map, I am finding that if a similarly named layer exists first in the TOC, then the FeatureLayer object gets set to it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="line-numbers language-csharp"&gt;&lt;CODE&gt;FeatureLayer sanForceMainLayer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;GetLayersAsFlattenedList&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;OfType&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;FeatureLayer&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Where&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;l &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; l&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Name&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;IndexOf&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"GISWRKS1.WORKS.ForceMain"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; StringComparison&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CurrentCultureIgnoreCase&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FirstOrDefault&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, if I have a TOC like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;layer1&lt;/P&gt;&lt;P&gt;layer2&lt;/P&gt;&lt;P&gt;GISWRKS1.WORKS.ForceMain_removals&lt;/P&gt;&lt;P&gt;layer4&lt;/P&gt;&lt;P&gt;layer5&lt;/P&gt;&lt;P&gt;GISWRKS1.WORKS.ForceMain&lt;/P&gt;&lt;P&gt;layer7&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case, sanForceMainLayer is getting set to 'GISWRKS1.WORKS.ForceMain_removals'.&amp;nbsp; I am expecting it to match exactly to 'GISWRKS1.WORKS.ForceMain'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2018 20:43:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826756#M3085</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2018-06-12T20:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: First or Default</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826757#M3086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Brian, just change your test from "IndexOf" to "==" or string.Compare. Currently, you are testing for any layer that contains the string "GISWRKS1.WORKS.ForceMain" which is not what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p.s. As an alternative, you can also include lambdas in most all LINQ extensions if you want to make your statements more concise...[for example Where(x =&amp;gt; x == 1).FirstOrDefault() versus FirstOrDefault(x =&amp;gt; x == 1)]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/8059285/c-sharp-linq-whereexpression-firstordefault-vs-firstordefaultexpression"&gt;https://stackoverflow.com/questions/8059285/c-sharp-linq-whereexpression-firstordefault-vs-firstordefaultexpression&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jun 2018 17:21:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826757#M3086</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2018-06-13T17:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: First or Default</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826758#M3087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Brian,&lt;/P&gt;&lt;P&gt;Working as intended?&lt;/P&gt;&lt;P&gt;&lt;A href="https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&amp;amp;l=EN-US&amp;amp;k=k(System.String.IndexOf);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.6.1);k(DevLang-csharp)&amp;amp;rd=true" rel="nofollow noopener noreferrer" target="_blank"&gt;IndexOf &lt;/A&gt;for strings reports the occurrence of string in the current string object.&lt;/P&gt;&lt;P&gt;If you had said IndexOf("a") it would have returned Layer1 for example.&lt;/P&gt;&lt;P&gt;You need to check if one string equals another so you could use either:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; lyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MapView&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Active&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;GetLayersAsFlattenedList&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Where&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;l &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; l&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Name&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;ToLower&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"streams"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FirstOrDefault&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; lyr2 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MapView&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Active&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FindLayers&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"streams"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FirstOrDefault&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Include .OfType&amp;lt;FeatureLayer&amp;gt; as needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You asked a related question last year: &lt;A _jive_internal="true" href="https://community.esri.com/thread/200221-does-a-certain-layer-exist-in-map" target="_blank"&gt;Does a certain layer exist in map&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Sean&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:57:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826758#M3087</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T09:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: First or Default</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826759#M3088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks &lt;A href="https://community.esri.com/migrated-users/23448"&gt;Charles Macleod&lt;/A&gt;‌ and &lt;A href="https://community.esri.com/migrated-users/3324"&gt;Sean Jones&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I'm really just a part-time coder I had no idea that this was connected to LINQ, so I wasn't really sure where to start looking for answers.&amp;nbsp; I will definitely investigate LINQ now that I know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've really just been using the method Sean talks about when he mentions my 'related question', but now that I know how to structure the command and what the l =&amp;gt; l == l is all about, I can definitely make some changes to how I do things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I ended up with in the end:&lt;/P&gt;&lt;PRE class="line-numbers language-csharp"&gt;&lt;CODE&gt;FeatureLayer sanForceMainLayer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;GetLayersAsFlattenedList&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;OfType&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;FeatureLayer&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Where&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;l &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; l&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Name &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"GISWRKS1.WORKS.ForceMain"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FirstOrDefault&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jun 2018 18:29:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/first-or-default/m-p/826759#M3088</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2018-06-13T18:29:42Z</dc:date>
    </item>
  </channel>
</rss>

