Broadly speaking, "this" is here, "that" is there. You use "this" when you are speaking about something already in your possession, with you, in front of you, or highlighted in some way; you use "there" when you are speaking about something that you have pointed to, something in the past, previously mentioned, or elsewhere.
For example, if you had a friend standing right next to you, and you introduced the friend to someone else, you would say "this is my friend". However, if you pointed out your friend from the other side of the room you would say "that is my friend".
In your example, when you have just presented an example and then ask a question about it, to be honest, you could use either this or that. There is an argument you should use that because you are referring back to something you just said (so it is in the past). Equally strong is the argument that you have just put something in front of the reader, and as the example is all part of the question, you should use this.
Note that it is idiomatic to say "this and that" together to refer to two alternatives, for example:
-What's in your stew?
-Oh, a bit of this and a bit of that.
This is just an expression to denote various different things.