I have written earlier in C/C++ but currently, I need it to convert into C#.
Can anyone tell me the code/way How to write drivers in C#?
Actually currently I
It's unclear from your description whether you intend to develop Windows device drivers or to interact with hardware through existing device drivers.
For example, to interact with devices connected to your serial port, you don't need to write your own driver and in fact, you can access it through .NET's SerialPort class.
Even USB devices can be accessed from user space (and, ultimately, managed code) through frameworks such as libusb-win32, WinUSB etc.