static void Snippet3() { CalculateArea objCalculateArea = new CalculateArea(Cube.Area); CalculateVolume objCalculateVolume = new CalculateVolume(Cube.Volume); Console.WriteLine("Surface Area of Cube: " + objCalculateArea(200.32)); Console.WriteLine("Volume of Cube: " + objCalculateVolume(20.56)); }
static void Main(string[] args) { CalculateArea objCalculateArea = new CalculateArea(Area); CalculateVolume objCalculateVolume = new CalculateVolume(Volume); Console.WriteLine("Surface Area of Cube: " + objCalculateArea(200.32)); Console.WriteLine("Volume of Cube: " + objCalculateVolume(20.56)); }
static void Main(string[] args) { CalculateArea objArea = new CalculateArea(Area); CalculateVolume objVolume = new CalculateVolume(Volume); Console.WriteLine(objArea(200.32)); Console.WriteLine(objVolume(20.56)); }
public void TestMethodCircle() { LibraryCalculatingArea.CalculateArea calculate = new CalculateArea(); double radius = 2.3; double areaC = calculate.AreaCircle(radius); Assert.AreEqual(areaC, Math.PI * Math.Pow(2.3, 2)); }
public static void Example1() { //Both of the following instantiations are same CalculateArea ca = DelegatesExamples.RectangleArea; var ca2 = new CalculateArea(DelegatesExamples.RectangleArea); Console.WriteLine("Rectangle 1 Area: {0}", ca(5, 8)); Console.WriteLine("Rectangle 2 Area: {0}", ca2(6, 12)); }
public void TestMethodTriangle() { LibraryCalculatingArea.CalculateArea calculate = new CalculateArea(); double a = 3; double b = 4; double c = 5; Tuple <double, bool> areaT = calculate.AreaTriangle(a, b, c).ToTuple <double, bool>(); double p = (a + b + c) / 2; double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c)); Tuple <double, bool> res = Tuple.Create(s, true); Assert.AreEqual(areaT, res); }
public static void DelegateTarget() { CalculateArea ca = DelegatesExamples.RectangleArea; var shape = new Shape(); CalculateArea ca2 = shape.Area; Console.WriteLine("First Delegate:"); Console.WriteLine("Rectangle Area: {0}", ca(5, 6)); Console.WriteLine("Method: {0}", ca.Method); Console.WriteLine("Target: {0}", ca.Target); Console.WriteLine("\n\nSecond Delegate:"); Console.WriteLine("Rectangle Area: {0}", ca2(6, 8)); Console.WriteLine("Method: {0}", ca2.Method); Console.WriteLine("Target: {0}", ca2.Target); if (ca2.Target == shape) { Console.WriteLine("This delegate's target is Shape Object."); } }
private PlateModel analyticalPaper(string url) { //DateTime beforDT = System.DateTime.Now; PlateModel plate = new PlateModel(); string[] urlStr = url.Split('\\'); string[] nameAndNum = urlStr[urlStr.Length - 1].Split('-'); plate.PlateName = nameAndNum[0]; plate.PlateCode = nameAndNum[0]; plate.PlateCount = int.Parse(nameAndNum[1].Substring(0, nameAndNum[1].Length - 4)); #region 加载dxf文件,获取文件每行的内容 List <string> listDxfInfo = new List <string>(); StreamReader sr = new StreamReader(url, Encoding.Default); String input; while ((input = sr.ReadLine()) != "EOF") { listDxfInfo.Add(input); } listDxfInfo.Add("EOF"); sr.Close(); #endregion #region 提取需要的信息内容,这里按图形和文字进行分类提取 List <string> listLine = new List <string>(); //直线类型 List <string> listCircle = new List <string>(); //圆类型 List <string> listArc = new List <string>(); //圆弧类型 List <string> listEllipse = new List <string>(); //椭圆类型 List <string> listText = new List <string>(); //单行文字类型 List <string> listMtext = new List <string>(); //多行文字类型 List <string> listLayer = new List <string>(); //图层信息 Dictionary <string, string> layerNandC = new Dictionary <string, string>(); //图层颜色和信息 for (int i = 0; i < listDxfInfo.Count; i++) { string s1 = listDxfInfo[i].Trim(); string s2 = listDxfInfo[i = i + 1].Trim(); if ("LAYER".Equals(s2) && "0".Equals(s1)) { List <string> getList = createListByClass(i - 1, listDxfInfo); listLayer.AddRange(getList); i = i + getList.Count - 2; getList.Clear(); } else if ("LINE".Equals(s2) && "0".Equals(s1)) { List <string> getList = createListByClass(i - 1, listDxfInfo); listLine.AddRange(getList); i = i + getList.Count - 2; getList.Clear(); } else if ("CIRCLE".Equals(s2) && "0".Equals(s1)) { List <string> getList = createListByClass(i - 1, listDxfInfo); listCircle.AddRange(getList); i = i + getList.Count - 2; getList.Clear(); } else if ("ARC".Equals(s2) && "0".Equals(s1)) { List <string> getList = createListByClass(i - 1, listDxfInfo); listArc.AddRange(getList); i = i + getList.Count - 2; getList.Clear(); } else if ("ELLIPSE".Equals(s2) && "0".Equals(s1)) { List <string> getList = createListByClass(i - 1, listDxfInfo); listEllipse.AddRange(getList); i = i + getList.Count - 2; getList.Clear(); } else if ("TEXT".Equals(s2) && "0".Equals(s1)) { List <string> getList = createListByClass(i - 1, listDxfInfo); listText.AddRange(getList); i = i + getList.Count - 2; getList.Clear(); } else if ("MTEXT".Equals(s2) && "0".Equals(s1)) { List <string> getList = createListByClass(i - 1, listDxfInfo); listMtext.AddRange(getList); i = i + getList.Count - 2; getList.Clear(); } } listDxfInfo.Clear(); #endregion #region 利用GDI+在自己的cad面板中画出提取出的内容 if (listLayer.Count > 0) { layerNandC = new LayerTool().getLayer(listLayer); } if (listLine.Count > 0) { plate.OutModel.ListShape.AddRange(new LineTool().getLineByColor(listLine, layerNandC)); } if (listCircle.Count > 0) { plate.OutModel.ListShape.AddRange(new CircleTool().getLineByColor(listCircle, layerNandC)); } if (listArc.Count > 0) { plate.OutModel.ListShape.AddRange(new ArcTool().getLineByColor(listArc, layerNandC)); } //if (listText.Count > 0) { new TextTool().createText(listText); } if (listEllipse.Count > 0) { plate.OutModel.ListShape.AddRange(new EllipseTool().getLineByColor(listEllipse, layerNandC)); } #endregion listEllipse.Clear(); listText.Clear(); listArc.Clear(); listCircle.Clear(); listLine.Clear(); listLayer.Clear(); layerNandC.Clear(); ModelOper modelOper = new ModelOper(); plate = modelOper.baseShapeSort(plate); for (int k = 0; k < plate.InnerModel.Count; k++) { plate.InnerModel[k] = modelOper.reSetPointShunXu(plate.InnerModel[k], false); } //for (int i = 0; i < plate.InnerModel[0].ListShape.Count; i++) //{ // Console.WriteLine("{0},{1},{2}", // plate.InnerModel[0].ListShape[i].ShapeClass, plate.InnerModel[0].ListShape[i].StartPoint, plate.InnerModel[0].ListShape[i].EndPoint); //} //CADInterface.currentPlates.Add(plate.OutModel); //这里不存在外围面域,下面的判断之后才选定外围面域 CADInterface.currentPlates.AddRange(plate.InnerModel); CADInterface.DrawShap(); plate = modelOper.reSetOutInner(plate); plate = modelOper.juedeIsArc(plate); plate = new CalculateArea().getPlateArea(plate); plate = new CalculateArea().getPlateBound(plate); plate = new CreateCenterPoint().getRotateCenter(plate); plate = new CreateCenterPoint().getPowCenter(plate); //DateTime afterDT = System.DateTime.Now; //TimeSpan ts = afterDT.Subtract(beforDT); //Console.WriteLine("件号:{0},时间:{1}", // plate.PlateName, ts.TotalSeconds); return(plate); //DateTime afterDT = System.DateTime.Now; //TimeSpan ts = afterDT.Subtract(beforDT); //MessageBox.Show("DateTime总共花费:" + ts.TotalMilliseconds); }