Beispiel #1
0
        static void Main(string[] args) //program starts at main.
        {
            myClass a = new myClass (2,6);
            Console.WriteLine(a);
            myClass b;
            b =a; //both a and b are pointing to the same memory location.
            b.x *=3;
            Console.WriteLine(a); //copied the reference... if you change the object, a refers to the same object as b and you get the same output.

            myStruct p = new myStruct(8,7);

            Console.WriteLine(p);

            myStruct q;
            q = p;
            Console.WriteLine(p);
            Console.WriteLine(q);
            q.a *= -2;
            Console.WriteLine(p);
            Console.WriteLine(q);

            anotherClass.count = 2;
            Console.WriteLine("anotherClass.x= ", anotherClass.count );

            anotherClass o1 = new anotherClass();
            anotherClass o2 = new anotherClass();
            anotherClass o3 = new anotherClass();

            o1.y = 10;
            o2.y = -4;
            Console.WriteLine("o2.x:=" + o2.y);

        }
Beispiel #2
0
 private static void myMethod(ref myStruct myStruct)
 {
     Console.WriteLine($"In myMethod, before change, MyInt1: " +
                       $"{myStruct.MyInt1} and MyInt2: {myStruct.MyInt2}");
     myStruct.MyInt1 = 10;
     Console.WriteLine($"In myMethod, after change, MyInt1: " +
                       $"{myStruct.MyInt1} and MyInt2: {myStruct.MyInt2}");
 }
            public static void TestIt()
            {
                myStruct ms = new myStruct();

                ms.X = 5;
                ms.DisplayX();
                Console.WriteLine("The getter returns: {0}", ms.X);
            }
        public Parser(string input)
        {
            Init();
            input += "+0";
            string replace = "func";

            FindArg(ref input, funcArray, replace);
            FindOP(ref input, '^', funcArray, replace);
            FindOP(ref input, '*', funcArray, replace);
            FindOP(ref input, '/', funcArray, replace);
            FindOP(ref input, '-', funcArray, replace);
            FindOP(ref input, '+', funcArray, replace);


            replace = "mfunc";
            for (int i = 0; i < funcArray.Count; i++)
            {
                string func = funcArray[i];
                int    result;
                funcArrI.Add(new List <string>());
                parssed.Add(new List <myStruct>());

                if (Int32.TryParse(func, out result) || func == "x")
                {
                    myStruct my = new myStruct();
                    my.arg1 = func;
                    parssed[i].Add(my);
                }
                else
                {
                    FindArg(ref func, funcArrI[i], replace);
                    FindOP(ref func, '^', funcArrI[i], replace);
                    FindOP(ref func, '*', funcArrI[i], replace);
                    FindOP(ref func, '/', funcArrI[i], replace);
                    FindOP(ref func, '+', funcArrI[i], replace);
                    FindOP(ref func, '-', funcArrI[i], replace);

                    Regex argument = new Regex(@"([\+\^\*\-\/])", RegexOptions.Compiled);
                    for (int j = 0; j < funcArrI[i].Count; j++)
                    {
                        string[] s  = argument.Split(funcArrI[i][j]);
                        myStruct my = new myStruct();
                        if (s.Length == 1)
                        {
                            my.arg1 = s[0];
                        }
                        else
                        {
                            my.arg1 = s[0];
                            my.op   = s[1];
                            my.arg2 = s[2];
                        }
                        parssed[i].Add(my);
                    }
                }
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            myStruct c = new myStruct();

            c.MyInt1 = 100;
            c.MyInt2 = 200;
            Console.WriteLine($"In Main, before change, MyInt1: " +
                              $"{c.MyInt1} and MyInt2: {c.MyInt2}");
            myMethod(ref c);
            Console.WriteLine($"In Main, after change, MyInt1: " +
                              $"{c.MyInt1} and MyInt2: {c.MyInt2}");
        }
Beispiel #6
0
    static void Main()
    {
        // let's do some math.

        myStruct ms = new myStruct(), ms2;

        ms.Array = new double[1];

        ms.Length   = 1;
        ms.Array[0] = 424.444;

        ms2 = myStruct.MarshalIn(doSomething(ms.MarshalOut(), 524.444));

        // Free this after the call.
        ms.Free();
    }
Beispiel #7
0
        static void Main(string[] args)
        {
            MyClass objectA = new MyClass();
            MyClass objectB = objectA;

            objectA.val = 10;
            objectB.val = 20;
            myStruct structA = new myStruct();
            myStruct structB = structA;

            structA.val = 30;
            structB.val = 40;
            Console.WriteLine("ObjectA.val = {0}", objectA.val);
            Console.WriteLine("ObjectB.val = {0}", objectB.val);
            Console.WriteLine("structA.val = {0}", structA.val);
            Console.WriteLine("structB.val = {0}", structB.val);
        }
Beispiel #8
0
        static void Main(string[] args) //program starts at main.
        {
            myClass a = new myClass (2,6);
            Console.WriteLine(a);
            myClass b;
            b =a; //both a and b are pointing to the same memory location.
            b.x *=3;
            Console.WriteLine(a); //copied the reference... if you change the object, a refers to the same object as b and you get the same output.

            myStruct p = new myStruct(8,7);

            Console.WriteLine(p);

            myStruct q;
            q = p;
            Console.WriteLine(q);
        }
Beispiel #9
0
        /// <summary>
        /// Custom marshal a structure in from interop (and optionally free the original pointer).
        /// </summary>
        /// <param name="ptr"></param>
        /// <param name="freeOrig"></param>
        /// <returns></returns>
        public static myStruct MarshalIn(IntPtr ptr, bool freeOrig = true)
        {
            byte[]   by = new byte[4];
            myStruct ns = new myStruct();

            Marshal.Copy(ptr, by, 0, 4);
            ns.Length = BitConverter.ToInt32(by, 0);

            ns.Array = new double[ns.Length];
            by       = new byte[ns.Length * 8];

            Marshal.Copy(ptr + IntPtr.Size, by, 0, by.Length);
            Buffer.BlockCopy(by, 0, ns.Array, 0, by.Length);
            if (freeOrig)
            {
                Marshal.FreeHGlobal(ptr);
            }

            return(ns);
        }
            public static int Main_old()
            {
                myStruct[] arr = new myStruct[10];

                return 0;
            }
        public BaseModule() : base()
        {

            Dictionary<string, string> dic = new Dictionary<string, string>{{"1","A"}, {"2","B"}};
            Bootstrapper bt = new Bootstrapper();
            bt.Dispose();
            state xs;
            xs = state.red;
            xs.ToString();
            statelist s;
            s.sa = xs;

            int[] array = new int[5] { 1, 2, 3, 4, 5 };

            h = new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 1, 2, 3, 4 } };

            intArray = new int[2][];
            intArray = new int[2][] { new int[] { 1, 2, 3 }, new int[] { 2, 3, 4 } };

            intArray[0] = new int[5];
            intArray[1] = new int[4];

            int[][] intArray2 = { new int[] { 1, 2, 3 }, new int[] { 2, 3, 4 } };

            string arrayStr = "";
            foreach (int[] item in intArray2)
            {
                foreach (int i in item)
                {
                    arrayStr += i + ".";
                }
            }

            MyClass objectA = new MyClass();
            MyClass objectB = new MyClass();

            MyClass.vfun();

            objectA.val = 10;
            objectB.val = 20;
            myStruct structA = new myStruct();
            myStruct structB = new myStruct();
            structA.val = 30;
            structB.val = 40;
            string obstr = objectA.val + "." + objectB.val + "." + structA.val + "." + structB.val;

            ViewsModel.UserInfo ui = (ViewsModel.UserInfo)new ViewsModel.UserInfo().installUser(new ViewsModel.UserInfo() { passWord  = "******", userName = "******" });



        }