Save a recorded sound to .wav

I have made a script that records sound in my Unity game and I want to save the recording to a .wav file
I found a solution regarding this but that is in C language, so can you help me in converting the C script to a C# script.
This is the script I used for recording.
RecordMic.txt (4.2 KB)
solution in C language