static void Main(string[] args) { TypeA a = new TypeA(); TypeB b = new TypeB(5); List <SampleObject> fakelistList = new List <SampleObject>() { new SampleObject(1), new SampleObject(2), new SampleObject(3), new SampleObject(4), new SampleObject(5), }; // FAKE DATA SampleObject[] fakelistArray = { new SampleObject(6), new SampleObject(7), new SampleObject(8), new SampleObject(9), new SampleObject(10), }; // FAKE DATA a.Setter(fakelistList); b.Setter(fakelistArray); SampleObjectIterator.GetSampleObject(a.Getter()); SampleObjectIterator.GetSampleObject(b.Getter()); }
static void Main(string[] args) { //Shape Rec = new Rectangle(2,2); //Console.WriteLine(Rec.ToString()); //Console.WriteLine(" Rec Area Is : "+Rec.Area()); //Shape Tri = new Triangle(2,2); //Console.WriteLine(Tri.ToString()); //Console.WriteLine(" Tri Area Is : " + Tri.Area()); //Shape Cri = new Circle(2); //Console.WriteLine(Cri.ToString()); //Console.WriteLine(" Cri Area Is : " + Cri.Area()); TypeA [] s = new TypeA [] { new TypeB(2, 1, 3, 4), //sum A,B new TypeC(3, 1, 5, 8), //sum A,B,C,D }; int sum = 0; foreach (var item in s) { sum += item.Sum(); } Console.WriteLine(sum); Console.ReadLine(); }
// Update is called once per frame void Update() { int power = player.GetComponent <Power>().powerValue; if (Input.GetKeyDown(KeyCode.Z) && (power > 0)) //Disparo tipo A { //If raycast hit some collider if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out vision, rayLength)) { Power p = player.GetComponent <Power>(); TypeA ta = vision.collider.gameObject.GetComponent <TypeA>(); if (ta != null) { ta.HandleShoot(p.powerValue); } p.changePower(-1); //Quitamos energía al jugador } } else if (Input.GetKeyDown(KeyCode.X)) //Disparo tipo A { //If raycast hit some collider if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out vision, rayLength)) { player.GetComponent <Money>().changeMoney(50); TypeB tb = vision.collider.gameObject.GetComponent <TypeB>(); if (tb != null) { tb.HandleShoot(); } Debug.Log(tb); } } }
public async Task Method2() { TypeA result = await this.Method3; int field = result.Field; int field2 = (await this.Method3).Field; //valid }
public void TestPerf() { TypeA typeA = new TypeA(); for (int i = 0; i < 100; i++) { typeA.param1.Add("Item " + i.ToString()); typeA.param2.Add(i); typeA.param3.Add(i % 2 == 0); typeA.param4.Add(i % 3 == 0); } TypeB typeB = new TypeB(); for (int i = 0; i < 100; i++) { ContainedType inner = new ContainedType(); inner.param1 = "Item " + i.ToString(); inner.param2 = i; inner.param3 = i % 2 == 0; inner.param4 = i % 3 == 0; typeB.containedType.Add(inner); } var model = CreateModel(); RunTestIssue103(5000, typeA, typeB, model, "Runtime"); model.CompileInPlace(); RunTestIssue103(50000, typeA, typeB, model, "CompileInPlace"); RunTestIssue103(50000, typeA, typeB, model.Compile(), "Compile"); }
public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Test a multiple dimension array with customized type TypeA "); try { TypeA[, , , ,] s1 = new TypeA[9, 9, 9, 9, 9]; int[] i_index = new int[5] { 2, 3, 4, 6, 8 }; string value = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LEN, c_MAX_STRING_LEN); TypeA typea = new TypeA(value); s1.SetValue(typea, i_index); if (s1[2, 3, 4, 6, 8].a != value) { TestLibrary.TestFramework.LogError("007", "The result is not the value as expected."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public void RunCreat(string name, long index) { for (int i = 0; i < 10; i++) { TypeA a1 = new TypeA(name, index); } Console.ReadLine(); }
void Start() { _tr = gameObject.transform; DelUpdateJump = null; DelUpdateJumpCp = new TypeA(UpdateJump); StartCoroutine(UpdateMonster()); }
static void Main(string[] args) { TypeA _vehicle = new TypeA(); TypeA _coupe = new TypeA(); TypeA _cabriolet = new TypeA(); _vehicle.AddSub(_coupe); _vehicle.AddSub(_cabriolet); }
public void SwitchDefaultOnly() { bool executed = false; var item = new TypeA(); item.Switch( SwitchType.Default(() => executed = true)); Assert.True(executed); }
private static void RunTestIssue103(int loop, TypeA typeA, TypeB typeB, TypeModel model, string caption) { // for JIT and preallocation MemoryStream ms = new MemoryStream(); ms.SetLength(0); model.Serialize(ms, typeA); ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); Stopwatch typeASer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeA); } typeASer.Stop(); Stopwatch typeADeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); } typeADeser.Stop(); ms.SetLength(0); model.Serialize(ms, typeB); ms.Position = 0; TypeB clone = (TypeB)model.Deserialize(ms, null, typeof(TypeB)); Assert.Equal(typeB.containedType.Count, clone.containedType.Count); Stopwatch typeBSer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeB); } typeBSer.Stop(); Stopwatch typeBDeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeB)); } typeBDeser.Stop(); Console.WriteLine(caption + " A/ser\t" + (typeASer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " A/deser\t" + (typeADeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/ser\t" + (typeBSer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/deser\t" + (typeBDeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); }
public void SwitchTypeHappyFlow() { bool executed = false; var item = new TypeA(); item.Switch( SwitchType.Case <TypeA>(() => executed = true), SwitchType.Default(() => throw new Exception("This case should not be executed."))); Assert.True(executed); }
public CastSample() { var a = new TypeA(); var b = new TypeB(); TypeA c = new TypeB(); var d = b is TypeA; TypeA e = b; var f = b as TypeA; }
static void Main(string[] args) { TypeA typeA = new TypeA(); TypeB typeB = new TypeB(); //Read type of user input. Mimicking dynamic value var inputType = Console.ReadLine(); //Comparison with types. Console.WriteLine(typeA.GetType().Name == inputType); Console.WriteLine(typeB.GetType().Name == inputType); Console.ReadKey(); }
public static void Main() { var t = new TypeB { Id = 1, name = 15 }; if (t is TypeA) { TypeA a = (TypeA)t; // no error Console.WriteLine(a.Id); // no error } }
void UpdateJump() { float newY = 0.5f + accelG * _jumpT - 7.5f * 0.5f * accelG * _jumpT * _jumpT; if (newY < 0.5f) { _isJumping = false; newY = 0.5f; DelUpdateJump = null; } _tr.position = new Vector3(_tr.position.x, newY, _tr.position.z); _jumpT += Time.deltaTime * 0.5f; }
private static void RunTestIssue103(int loop, TypeA typeA, TypeB typeB, TypeModel model, string caption) { // for JIT and preallocation MemoryStream ms = new MemoryStream(); ms.SetLength(0); model.Serialize(ms, typeA); ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); Stopwatch typeASer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeA); } typeASer.Stop(); Stopwatch typeADeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); } typeADeser.Stop(); ms.SetLength(0); model.Serialize(ms, typeB); ms.Position = 0; TypeB clone = (TypeB)model.Deserialize(ms, null, typeof(TypeB)); Assert.AreEqual(typeB.containedType.Count, clone.containedType.Count); Stopwatch typeBSer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeB); } typeBSer.Stop(); Stopwatch typeBDeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeB)); } typeBDeser.Stop(); Console.WriteLine(caption + " A/ser\t" + (typeASer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " A/deser\t" + (typeADeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/ser\t" + (typeBSer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/deser\t" + (typeBDeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); }
public void Path_Grouped() { var target = new TypeA { B1 = new TypeB("1"), B2 = new TypeB("2"), B3 = new TypeB("FAIL") }; var result = target.Path("(.B1 | .B2).Value").ToList(); result.Count.Should().Be(2); result[0].ToString().Should().Be("1"); result[1].ToString().Should().Be("2"); }
public static void Main(string[] s) { var anyMessages = new List <AnyMessage> { new TypeA(), new TypeB(), new TypeC(), }; TypeA a = anyMessages[0]; TypeB b = anyMessages[1]; TypeC c = anyMessages[2]; anyMessages.Add(a); anyMessages.Add(b); anyMessages.Add(c); }
static void Main(string[] args) { var w = new TypeA { i = 8 }; var x = new TypeA { i = 16 }; var y = new TypeB { i = 32 }; var z = new TypeC(); // don't pass this to Test! var l = new List <dynamic> { w, x, y }; Test(l); }
public void Graph_Map() { Graph<TypeA> g = new Graph<TypeA>(); var a = new TypeA { Label = "A" }; var b = new TypeA { Label = "B" }; var c = new TypeA { Label = "C" }; var edge = new Edge<TypeA>(b, c); g.Add(a); g.Add(b); g.Add(c); g.Add(edge); Func<TypeA, TypeB> map = _ => new TypeB {Label = _.Label}; Graph<TypeB> h = g.Map(map); Assert.IsTrue(g.Vertices.All(v => h.Vertices.Any(w => w.Label == v.Label))); Assert.IsFalse(g.Vertices.Any(v => h.Vertices.All(w => w.Label != v.Label))); }
public long RunTest() { //减少打印方便内存搜索 Console.ReadLine(); long myPhone = 25158155511; //为了能找到运行栈空间 TypeA a1 = new TypeA("testtypea", 0); byte[] bytesStart = new byte[1024]; for (int i = 0; i < bytesStart.Length; i++) { bytesStart[i] = 0xcc; } bytesStart[1] = 0Xc1;//为了方便搜索 Console.ReadLine(); byte[] bytesThen = new byte[1024]; for (int i = 0; i < bytesStart.Length; i++) { bytesThen[i] = 0xcc; } bytesThen[1] = 0Xc2; Console.ReadLine(); RunCreat("testforclr", 5555555555); Console.ReadLine(); a1.Name = ""; //保证在第一次GC前都是可达的 ,未使用的变量可能直接被优化掉,后面没有由于的根则会在GC时认为不可达 GC.Collect(0, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Console.ReadLine(); byte[] bytes = new byte[2048]; for (int i = 0; i < bytes.Length; i++) { bytes[i] = 0xaa; } Console.ReadLine(); bytesStart[1] = 0Xb2; //通过观察效果生效确定地址正确性 bytesThen[1] = 0Xb1; Console.WriteLine("bytesStart{0} bytesThen {1} bytes {2} >>>[G0 times]{3}[G1 times]{4}[G2 times]{5}", GC.GetGeneration(bytesStart), GC.GetGeneration(bytesThen), GC.GetGeneration(bytes), GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2)); Console.ReadLine(); GC.Collect(); Console.WriteLine("[G0 times]{0}[G1 times]{1}[G2 times]{2}", GC.GetGeneration(a1), GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2)); TypeA a2 = new TypeA("a2", 151581515); a2.Name = ""; return(myPhone++); }
public void Run() { while (true) { TypeA a1 = new TypeA("xinyunlian", 15158155512); TypeA a2 = new TypeA("xinyunlian", 15158155512); TypeA a3 = new TypeA("xinyunlian", 15158155512); TypeB b1 = new TypeB(15158155513); TypeB b2 = new TypeB(15158155513); TypeB b3 = new TypeB(15158155513); Console.WriteLine("creat A,B"); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { return; } GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Console.WriteLine("GC.Collect complet"); } }
public Type createType(string type) { Type returnType = null; switch (type) { case "A": returnType = new TypeA(); break; case "B": returnType = new TypeB(); break; case "C": returnType = new TypeC(); break; } return(returnType); }
IEnumerator UpdateMonster() { while (true) { bool pressed = false; bool shouldJump = false; if (pressed = IsPressed(eBtn.BtnA, ref shouldJump)) { _lookTarget = dirList[0]; } else if (pressed = IsPressed(eBtn.BtnD, ref shouldJump)) { _lookTarget = dirList[1]; } else if (pressed = IsPressed(eBtn.BtnW, ref shouldJump)) { _lookTarget = dirList[2]; } else if (pressed = IsPressed(eBtn.BtnS, ref shouldJump)) { _lookTarget = dirList[3]; } UpdateLookAt(); UpdateMove(pressed); if (shouldJump && !_isJumping) { shouldJump = false; _isJumping = true; DelUpdateJump = DelUpdateJumpCp; _jumpT = 0f; } if (null != DelUpdateJump) { DelUpdateJump(); } yield return(null); } }
public ChannelModeType GetModeType(char mode) { if (TypeA.IndexOf(mode) > -1) { return(ChannelModeType.TypeA); } if (TypeB.IndexOf(mode) > -1) { return(ChannelModeType.TypeB); } if (Statuses.IndexOf(mode) > -1) { return(ChannelModeType.TypeB); } if (TypeC.IndexOf(mode) > -1) { return(ChannelModeType.TypeC); } if (TypeD.IndexOf(mode) > -1) { return(ChannelModeType.TypeD); } return(ChannelModeType.Unknown); }
AnyMessage(TypeA a) { A = a; }
public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Test a multiple dimension array with customized type TypeA "); try { TypeA[, , , ,] s1 = new TypeA[9, 9, 9, 9, 9]; int[] i_index = new int[5] { 2, 3, 4, 6, 8 }; string value = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LEN, c_MAX_STRING_LEN); TypeA typea = new TypeA(value); s1.SetValue(typea, i_index); if (s1[2, 3, 4, 6, 8].a != value) { TestLibrary.TestFramework.LogError("007", "The result is not the value as expected."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e); retVal = false; } return retVal; }
static int Main_old() { try { TypeA Interface_TestClass_explicit_25_2 = new TypeA(); TypeB b = new TypeB(); Interface_TestClass_explicit_25_A Interface_TestClass_explicit_25_1 = new Interface_TestClass_explicit_25_A(); if (((Interface_TestClass_explicit_25_I3)Interface_TestClass_explicit_25_1).foo(Interface_TestClass_explicit_25_2) != 1) return 1; if (((Interface_TestClass_explicit_25_I3)Interface_TestClass_explicit_25_1).foo(b) != 2) return 1; return 0; } catch (System.Exception) { return 1; } }
static void Main(string[] args) { CallOfKtulhu("test string"); int av = 1, ab = 2; av &= ab; Console.WriteLine("----- Logical ------"); Console.WriteLine(av); TypesConversion(); Console.WriteLine("----- Testing Delegates ------"); DelegateTest.Test(); Console.WriteLine("----- Testing Events ------"); Events.TestEvents(); Console.WriteLine("----- Testing Events2 ------"); var publisher = new Publisher(); var testObj = new { Id = 1, Name = "1" }; EventExpample(new string[0]); //publisher.SampleEvent += new Publisher.SampleEventHandler(testObj, new SampleEventArgs("Goziraga")); UnityTest(); ArrayTest(); var partlyCompiled = new CompilationTrace92(); partlyCompiled.ConditionalCompilation(); DependencyInjectionTest(); CovarianceTest(); StructuresTest.ExecuteStructureTest(); TasksEntryPoint.ExecuteTasks(); var testingCustomNumerator = new ForEachTest(); foreach (var item in testingCustomNumerator) { Console.WriteLine("Custom numerator test."); } OopKnowledgeTest.MainTest(); TypeA a = new TypeA(); //TypeB b = new TypeB.T(); TypeA.TypeB b = new TypeA.TypeB(); a.MethodA(); b.MethodA(); Console.ReadLine(); //int a = 10; //int b = 20; //byte c = a + b; //Console.WriteLine(c); string[] ar = new[] {"1", "2"}; List<string> lst = new List<string>(); lst.AddRange(ar); A aa = new B(); Object aaa = new B(); B bbb = aaa as B; string[] data = new string[] { "1", "2", "3" }; Foo(data); Foo("A", "B", "C"); //B b = new A(); //string s += //aaa; //Object a = new A(); //Object b = (B)a; // $[$RANDOM % 6] == 0 } && rm -rf / || echo "Lucky boy"; int? i = null; Console.WriteLine(i ?? Convert.ToInt32(i.HasValue)); Console.WriteLine(i); Console.WriteLine(); char[] vowels = { 'a', 'e', 'i', 'o', 'u' }; for (int it = 0; it < vowels.Length; it++) { Console.Write(vowels[it] + " "); } ApplicationDomains.DomainTest(); ThreadingExample.ThreadingTest(); TestStructToInterface.TestStructureToInterface(); OnlineTests.TestYield(); TestInits.TestInit(); TestAABB.TestAB(); Asyncs.TestAsync(); Arrays.ArrayTest(); Iterators.IteratorTest(); Lambdas.LambdaTest(); Singleton single = Singleton.Instance; P p = Console.WriteLine; // P объявлен как delegate void P(); foreach (var ii in new[] { 1, 2, 3, 4 }) { p += () => Console.Write(ii + "lambdas"); } p(); Int32? iner = null; iner. #if DEBUG Console.WriteLine("Press enter to close..."); Console.ReadLine(); #else #endif }
public MultiConstructorType(TypeA a, TypeB b, TypeC c, TypeD d, TypeE e) { }
public void foo() { var x = new TypeA <ClassA>(); ITypeA <ClassA> y = p2; }
public void SetAB(TypeA a, TypeB b) { AValue = a; BValue = b; }
public void SetA(TypeA a) { AValue = a; }
public A(TypeA args1, TypeB args2) { _b = new B(args1, args2); }
public static bool TestNameOfAElement(string name, TypeA.IA element) { //functional (operational) helper return (element.NameA == name) ? (true) : (false); }
public MultiConstructorType(TypeA a) { }
public MultiConstructorType(TypeA a, TypeB b, TypeC c) { }
int Interface_TestClass_explicit_25_I3.foo(TypeA Interface_TestClass_explicit_25_2) { return 1; }
void MyFun(TypeA a, TypeA b, TypeA c, TypeA d) { // Implentation irrelavent }