8
Answers

Expert to C# Help Me!

Chung Le Kha

Chung Le Kha

15y
2.6k
1
I am learning about the programming language C #. to the use of unsafe code and pointers in C #.
and this is all my code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
           
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        struct Location
        {
            public int X;
            public int Y;
        }
        unsafe static void Main(string[] args)
        {

            Location loc;

            loc.X = 100;

            loc.Y = 100;



            Location* loc_ptr;

            loc_ptr = &loc;

            Console.WriteLine("X = {0}", loc_ptr->X);



            loc_ptr->X = 200;

            Console.WriteLine("X = {0}", loc_ptr->X);

        }
    }
}
the code is in error as follows:
unsafe code may only appear if compiling with/unsafe
// I tried and then move consoleapplication but it failed. and error is so
//Hope the experts help answer helped me


Answers (8)
Next Recommended Forum