1.

When does the System.OutOfMemoryException occur in C#?

Answer»

The SYSTEM.OutOfMemoryException occurs when enough memory is not allocated.

Let US see an example:

USING System; using System.Text; namespace Application {   class Example {      static void Main(string[] args) {         try {            string deptname = "Tom";            string loc = "North";            StringBuilder s = new StringBuilder(deptname.Length, deptname.Length);            s.Append(deptname);            s.Insert(value: loc, INDEX: deptname.Length - 1, count: 1);         } catch (System.OutOfMemoryException e) {            Console.WriteLine("The following is the ERROR:");            Console.WriteLine(e);         }      }   } }

The example displays the Out Of Memory Exception:

The following is the error: System.OutOfMemoryException: Out of memory  at System.Text.StringBuilder.Insert (System.Int32 index, System.String value, System.Int32 count) [0x00065] in <902ab9e386384bec9c07fa19aa938869>:0  at Application.Example.Main (System.String[] args) [0x0002f] in <98ee8a52b3134b0799d382272292200f>:0


Discussion

No Comment Found