Samir Bhogayta
What is the use of fixed statement?
By Samir Bhogayta in C# on Jun 25 2016
  • Samir Bhogayta
    Jun, 2016 25

    The fixed statement sets a pointer to a managed variable and “pins” that variable during the execution of statement. Without fixed, pointers to managed variables would be of little use since garbage collection could relocate the variables unpredictably. (In fact, the C# compiler will not allow you to set a pointer to a managed variable except in a fixed statement.) Eg:Class A { public int i; } A objA = new A; // A is a .net managed type fixed(int *pt = &objA.i) // use fixed while using pointers with managed // variables { *pt=45; // in this block use the pointer the way u want }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS