Question: In this code fragment

```
foreach (var row in grid.Rows) { }              

```

the type of row is inferred as Object instead of GridViewRow. I have to explicitly declare the type to work with a GridViewRow:

```
foreach (GridViewRow row in grid.Rows) { }

```

GridView.Rows returns a GridViewRowCollection and GetEnumerator on the collection "Returns an enumerator that contains all GridViewRow objects in the GridViewRowCollection." If I access a single row from the collection by index

```
var row = grid.Rows[0];

```

the type is correctly inferred. Why can't the compiler infer the type for row in the foreach declaration?

Edited to add: Interesting responses, I didn't think to look for the obvious problem. ListView.Items implements `IList<ListViewDataItem>`, so this looks like an oversight to me.

Answer: 
### [Optional chaining operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining):

```js
const invoice = {customer: {address: {city: "foo"}}}

console.log( invoice?.customer?.address?.city )
console.log( invoice?.customer?.address?.street )
console.log( invoice?.xyz?.address?.city )
```

*[See supported browsers list](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#browser_compatibility)*

---

### For those which have `lodash` included in their project:There is a lodash [\_.get](https://lodash.com/docs/4.17.4#get) method which tries to get "deep" keys:

> 
> Gets the value at path of object. If the resolved value is undefined,
> the defaultValue is returned in its place.
> 
> 
> 

```js
var object = { 'a': [{ 'b': { 'c': 3 } }] };

console.log(
  _.get(object, 'a[0].b.c'),           // => 3
  _.get(object, ['a', '0', 'b', 'c']), // => 3
  _.get(object, 'a.b.c'),              // => undefined 
  _.get(object, 'a.b.c', 'default')    // => 'default'
)
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
```

---

This will effectively check if that key, however **deep**, is defined and *will not* throw an error which might harm the flow of your program if that key is not defined.
While this doesn't necessarily check if a key exists, it does check for the truthiness of a value. Which `undefined` and `null` fall under.

`Boolean(obj.foo)`

This solution works best for me because I use typescript, and using strings like so `'foo' in obj` or `obj.hasOwnProperty('foo')` 
 to check whether a key exists or not does not provide me with intellisense.