# Handle \_ in switch case

**URL:** <https://forum.golangbridge.org/t/handle-in-switch-case/13054>\
**Category:** Getting Help\
**Created:** [March 22, 2019, 8:41am UTC](https://forum.golangbridge.org/t/handle-in-switch-case/13054 "2019-03-22T08:41:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![akhilravuri](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/akhilravuri/32/10615_2.png) [@akhilravuri](https://forum.golangbridge.org/u/akhilravuri)\
**Post date:** [March 22, 2019, 8:41am UTC](https://forum.golangbridge.org/t/handle-in-switch-case/13054/1 "2019-03-22T08:41:32Z")

</div>

```go
package main

import "fmt"

func do(i interface{}) {
	switch a := i.(type) {
	case int:
		fmt.Printf("int")
	case string:
		fmt.Printf("string")
	default:
		fmt.Printf("I don't know about type")
	}
}

func main() {
	do(21)
	do("hello")
	do(true)
}

```

The above code will not work as var a is declared but not used.  
Switch case will not allow me to use \_.  
But I don’t want that data I just want that type.

can we do this in another way?

Thanks.

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/nobbz/32/3096_2.png) [@NobbZ](https://forum.golangbridge.org/u/NobbZ)\
**Post date:** [March 22, 2019, 10:02am UTC](https://forum.golangbridge.org/t/handle-in-switch-case/13054/2 "2019-03-22T10:02:45Z")

</div>

Just using `switch i.(type) { … }` works for me:

[https://play.golang.org/p/2d3n2\_fbqFk](https://play.golang.org/p/2d3n2_fbqFk)

---

<div class="post-metadata">

**Author:** ![akhilravuri](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/akhilravuri/32/10615_2.png) [@akhilravuri](https://forum.golangbridge.org/u/akhilravuri)\
**Post date:** [March 22, 2019, 10:04am UTC](https://forum.golangbridge.org/t/handle-in-switch-case/13054/3 "2019-03-22T10:04:30Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [June 20, 2019, 10:04am UTC](https://forum.golangbridge.org/t/handle-in-switch-case/13054/4 "2019-06-20T10:04:31Z")

</div>

Closed on June 20, 2019, 10:04am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
