AI代码带来的问题

2026/03 06 17:03
public static (int w, int h) ReadTgaSizeFast(string tgaFilePath)
{
	using (var fs = new FileStream(tgaFilePath, FileMode.Open, FileAccess.Read, FileShare.Read,
	    bufferSize: 4, FileOptions.SequentialScan | FileOptions.DeleteOnClose))
	{
		fs.Seek(12, SeekOrigin.Begin);
		byte[] buffer = new byte[4];
		int readBytes = fs.Read(buffer, 0, 4);
		var width = BitConverter.ToUInt16(buffer, 0);
		var height = BitConverter.ToUInt16(buffer, 2);

用deepseek写的读TGA文件的大小

当读取这个TGA后,文件就会被自动删除,人是不会写这种代码的;

所以使用AI要小心