What are managed and unmanaged resources? Which built-in method and interface we have for unmanaged resources?
Interviews1 answer
Managed and Unmanaged Resources in .NET
1 Answer
Managed resources are those that are pure.NET code and managed by the runtime and are under its direct control. Unmanaged resources are those that are not. File handles, pinned memory, COM objects, database connections etc
// using unmanaged code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Runtime.InteropServices;namespace DllImportSample{public partial class frmDllImportSample : Form{[DllImport("user32.dll")]private static extern int MessageBox(IntPtr hWnd, String lpText, String lpCaption, uint uType);public frmDllImportSample(){InitializeComponent();}private void btnMessageBox_Click(object sender, EventArgs e){MessageBox(new IntPtr(this.Handle.Int32()), @"Calling MessageBox Win32 API from C#", @"MessageBox", 0);System.Windows.Forms.MessageBox.Show(@"This is C# MessageBox!", @"MessageBox");}}}
Rajanikant HawaldarPosted Oct 13, 2022, 11:15 AM EDT

