简体   繁体   中英

Is FileStream a managed or unmanaged code?

I was asked this question in an interview and I said the answer was Managed. The interviewer seemed surprised. My question is even though it access a file (a native/unmanaged resource) but isn't this class Managed? Or do you think I should have some follow up questions to get more clarification?

According to ILSpy, FileStream contains an awful lot of managed code, so you could argue that it is managed. However, ultimately all file I/O must resolve down to Win32 P/Invoke calls, so you could argue that it is a wrapper round unmanaged code. It rather depends on your definitions.

You may take a look at the question

What is managed and unmanaged code?

From that discussion I would say it is managed code since you access and manage the resources through the .NET runtime

Typically all the code that runs by the CLR is considered managed at least in your perspective, outside to it, you have Win32 API, ActiveX, COM object these are Unmanaged.

AS FileStream is a class by .Net so it's a Managed Class / object. but its usaes some windows resource for that reason its unmanged and you must dispose its object after using it. .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM