I am required to create a display template programatically which is via visual studio and I am really new to this. Can anyone share with me a sample source code for creating display templates and how to use them in Sharepoint? Thanks in advance, appreciate it :)
The following article from official sources should give you a start.
There can be a fair bit involved depending on what you are trying to achieve. More often than not I find most customisation can start from an a copy of an existing template. This can be achieved by opening the Master Page Gallery-> Display Templates and copying an existing template. A template will generally consist of a *.html and *.js of which are both associated.
If you do wish to start from a blank display template I can recommend the following starter template from Elio Struyf.