public void Test7() { unsafe { IntPtr iptr = Marshal.AllocHGlobal(10000); Type5 type5 = new Type5() { dateTime = new DateTime(2001, 2, 3), number = 3012 }; void *ptr = iptr.ToPointer(); *(Type5 *)ptr = type5; Type5 type5b = *(Type5 *)ptr; Assert.AreEqual(type5, type5b); ptr = ((Type5 *)ptr) + 1; *(int *)ptr = 4391; Assert.AreEqual(4391, *(int *)ptr); ptr = ((Type5 *)ptr) - 1; type5b = *(Type5 *)ptr; Console.WriteLine(type5b.ToString()); Assert.AreEqual(type5, type5b); ptr = ((Type5 *)ptr) + 1; Assert.AreEqual(4391, *(int *)ptr); } }
List <Type_5> GetType5(short count, int offset, List <Type_5> Type5, int idx) { if (Type5 == null) { Type5 = new List <Type_5>(); } for (int i = 0; i < count; i++) { Type5.Add(new Type_5() { Idx = idx, I_00 = BitConverter.ToUInt16(rawBytes, offset + 0), I_02 = (ushort)(BitConverter.ToUInt16(rawBytes, offset + 2) - BitConverter.ToUInt16(rawBytes, offset + 0)), I_04 = BitConverter.ToUInt16(rawBytes, offset + 4), I_06 = BitConverter.ToUInt16(rawBytes, offset + 6), I_08 = BitConverter.ToUInt16(rawBytes, offset + 8), I_10 = BitConverter.ToUInt16(rawBytes, offset + 10), I_12 = BitConverter.ToUInt16(rawBytes, offset + 12), I_14 = BitConverter.ToUInt16(rawBytes, offset + 14), I_16 = BitConverter_Ex.ToInt32Array(rawBytes, offset + 16, 12) }); offset += 64; } return(Type5); }
public void Test6() { // Succeeds (but struct) unsafe { IntPtr iptr = Marshal.AllocHGlobal(10000); Type5 type5 = new Type5() { dateTime = new DateTime(2001, 2, 3), number = 3012 }; Marshal.StructureToPtr(type5, iptr, false); Type5 type5b = Marshal.PtrToStructure <Type5>(iptr); Assert.IsTrue(type5b.dateTime.Equals(new DateTime(2001, 2, 3)) && type5b.number.Equals(3012)); } }
private void cbQuestionList_SelectedIndexChanged(object sender, EventArgs e) { try { if (cbQuestionList.SelectedIndex > 0) { btnSubmit.Text = "Zapisz"; btnDelete.Enabled = true; short id = Convert.ToInt16(cbQuestionList.SelectedItem); Repository r = new Repository(connStr); DbQuestion q = r.GetQuestion(id); if (q.QType == 2) { cbQuestionType.SelectedIndex = 1; pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; pictureBox2.SizeMode = PictureBoxSizeMode.Zoom; // ciągniemy obrazki z bazy Image[] images = r.loadImages(q.ID); q.Image = images[0]; q.ImageAlt = images[1]; pictureBox1.Image = q.Image; pictureBox2.Image = q.ImageAlt; } else { cbQuestionType.SelectedIndex = 0; } cbAnswerType.SelectedIndex = (int)q.Type >= 6? (int)q.Type - 2: (int)q.Type - 1; richTextBox1.Text = q.question.Replace(replace2, replace1); richTextBox1.Text = richTextBox1.Text.ReplaceApostropheToSymbol(); type1.Dispose(); type2.Dispose(); type3.Dispose(); type4.Dispose(); type5.Dispose(); type6.Dispose(); Point point = new Point(250, richTextBox1.Size.Height + pictureBox1.Size.Height + lower); AnchorStyles anchor = AnchorStyles.Bottom | AnchorStyles.Left; switch (cbAnswerType.SelectedIndex) { case 0: type1 = new Type1(); type1.q = q; Controls.Add(type1); type1.Location = point; type1.Anchor = anchor; break; case 1: type2 = new Type2(); type2.q = q; Controls.Add(type2); type2.Location = point; type2.Anchor = anchor; break; case 2: type3 = new Type3(); type3.q = q; Controls.Add(type3); type3.Location = point; type3.Anchor = anchor; break; case 3: type4 = new Type4(); type4.q = q; Controls.Add(type4); type4.Location = point; type4.Anchor = anchor; break; case 4: type5 = new Type5(); type5.q = q; Controls.Add(type5); type5.Location = point; type5.Anchor = anchor; break; case 5: type6 = new Type6(); type6.q = q; Controls.Add(type6); type6.Location = point; type6.Anchor = anchor; break; default: break; } } else { cbQuestionType.SelectedIndex = 0; pictureBox1.Image = null; pictureBox2.Image = null; cbAnswerType_SelectedIndexChanged(sender, null); btnSubmit.Text = "Dodaj"; btnDelete.Enabled = false; richTextBox1.Text = ""; cbAnswerType.SelectedIndex = 1; //Domyslny typ2 przy wprowadzaniu nowego. (Jednego) } } catch (Exception ex) { reCounter++; if (reCounter == 5) { throw; } //Ponowna próba rekursywnie. cbQuestionList_SelectedIndexChanged(sender, e); } }
private void cbAnswerType_SelectedIndexChanged(object sender, EventArgs e) { try { type1.Dispose(); type2.Dispose(); type3.Dispose(); type4.Dispose(); type5.Dispose(); type6.Dispose(); Point point = new Point(250, richTextBox1.Size.Height + lower); AnchorStyles anchor = AnchorStyles.Bottom | AnchorStyles.Left; setRtbLocation(); switch (cbAnswerType.SelectedIndex) { case 0: type1 = new Type1(); Controls.Add(type1); type1.Location = new Point(250, richTextBox1.Size.Height + pictureBox1.Size.Height + lower); type1.Anchor = anchor; break; case 1: type2 = new Type2(); Controls.Add(type2); type2.Location = new Point(250, richTextBox1.Size.Height + pictureBox1.Size.Height + lower); type2.Anchor = anchor; break; case 2: type3 = new Type3(); Controls.Add(type3); type3.Location = new Point(250, richTextBox1.Size.Height + pictureBox1.Size.Height + lower); type3.Anchor = anchor; break; case 3: type4 = new Type4(); Controls.Add(type4); type4.Location = new Point(250, richTextBox1.Size.Height + pictureBox1.Size.Height + lower); type4.Anchor = anchor; break; case 4: type5 = new Type5(); Controls.Add(type5); type5.Location = new Point(250, richTextBox1.Size.Height + pictureBox1.Size.Height + lower); type5.Anchor = anchor; break; case 5: type6 = new Type6(); Controls.Add(type6); type6.Location = new Point(250, richTextBox1.Size.Height + pictureBox1.Size.Height + lower); type6.Anchor = anchor; break; default: break; } } catch { // Druga próba rekursywnie. cbAnswerType_SelectedIndexChanged(sender, e); } }
static void Main(string[] args) { //--------------------------------------------------------------- Type1 type1 = delegate(int x){ x = x + 1; Console.WriteLine(x); }; Type1 type11 = (a) => Console.WriteLine(a); Type1 type1Lambda = (x) => { x = x + 1; Console.WriteLine(x); }; //--------------------------------------------------------------- Type2 type2 = delegate(int x, string y) { Console.WriteLine(x); Console.WriteLine(y.Length); }; Type2 type2Lambda = (p1, p2) => { Console.WriteLine(p1); Console.WriteLine(p2.Length); }; //--------------------------------------------------------------- Type3 type3 = delegate(int x, int y) { return(x > y); }; Type3 type3Lambda1 = (x, y) => x > y; Type3 type3Lambda2 = (x, y) => { x = x + y; return(x > y); }; //---------------------------------------------------------------- GenericType3 <float> gtFloat = delegate(float x, float y) { return(x > y); }; GenericType3 <int> gtInt = delegate(int x, int y) { return(x > y); }; GenericType3 <string> gtString = delegate(string x, string y) { return(x.Length > y.Length); }; GenericType3 <float> gtFloatLambda = (a, b) => a > b; GenericType3 <int> gtIntLambda = (a, b) => a > b; GenericType3 <string> gtStringLambda = (a, b) => a.Length > b.Length; //------------------------------------------------------------------ //GenericType3<Person> personDelegate Person pe1 = new Person { Age = 10 }; Person pe2 = new Person { Age = 20 }; bool isPe1GTPe2 = ITakeGenericDelegate <Person>(pe1, pe2, (per1, per2) => per1.Age > per2.Age); //------------------------------------------------------------------- Person[] people = new Person[3] { new Person { Age = 10 }, new Person { Age = 20 }, new Person { Age = 30 } }; Human[] humansOldWay = Array.ConvertAll <Person, Human>(people, GetHumanFromPerson); Human[] humans = Array.ConvertAll <Person, Human>(people, (person) => new Human { AgeInMonths = person.Age * 12 }); //---------------------------------Variable Capture------------------- Type4 cl = inc(); var res1 = cl(); var res2 = cl(); //-------------------------------------------------------------------- Type5[] t51 = new Type5[10]; for (int i = 0; i < 10; i++) { //int temp = i; t51[i] = () => Console.WriteLine(i); } foreach (Type5 t in t51) { t(); } //-------------------------------------------------------------------- ExpressionTreeExample(); Console.ReadLine(); }
private class Requires8 { public Requires8(Type1 p1, Type2 p2, Type3 p3, Type4 p4, Type5 p5, Type6 p6, Type7 p7, Type8 p8) { }
private class Requires7 { public Requires7(Type1 p1, Type2 p2, Type3 p3, Type4 p4, Type5 p5, Type6 p6, Type7 p7) { }
private class Requires6 { public Requires6(Type1 p1, Type2 p2, Type3 p3, Type4 p4, Type5 p5, Type6 p6) { }
private class Requires5 { public Requires5(Type1 p1, Type2 p2, Type3 p3, Type4 p4, Type5 p5) { }