string cat and singeltonpattern

This commit is contained in:
test 2019-04-06 11:24:54 +02:00
parent f3b83da865
commit 736857b680
25 changed files with 225 additions and 30 deletions

View File

@ -1,14 +1,21 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ClassLibrary01 namespace ClassLibrary01
{ {
public class Class1 public class Class1 :IDisposable
{ {
public void DoIt()
{
var foo = SingeltonPattern.GetInstance();
}
public int Add(int i1, int i2 = 10) public int Add(int i1, int i2 = 10)
{ {
return i1 + i2; return i1 + i2;
@ -19,5 +26,20 @@ namespace ClassLibrary01
return Add(i1, 10); return Add(i1, 10);
} }
private Pen _pen;
public void Dispose()
{
_pen.Dispose();
}
public Pen getPen()
{
_pen = new Pen(Color.Black, 2);
return _pen;
}
} }
} }

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>4859a826-18e2-4c0c-a441-f77975e70e93</ProjectGuid> <ProjectGuid>{4859A826-18E2-4C0C-A441-F77975E70E93}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClassLibrary01</RootNamespace> <RootNamespace>ClassLibrary01</RootNamespace>
@ -31,24 +31,20 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System"/> <Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Core"/> <Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq"/> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions"/> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="Microsoft.CSharp"/> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Data"/>
<Reference Include="System.Net.Http"/>
<Reference Include="System.Xml"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Class1.cs" /> <Compile Include="Class1.cs" />
<Compile Include="CodeFile1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -0,0 +1,33 @@

using System.Runtime.CompilerServices;
public class SingeltonPattern
{
private static SingeltonPattern _singelton;
private SingeltonPattern()
{
}
public static SingeltonPattern GetInstance()
{
if (_singelton == null)
{
_singelton = new SingeltonPattern();
}
return _singelton;
}
}

View File

@ -1 +1 @@
69d79abfd67c28b98a7f19e87fceac8121786190 165664fdbdaecd0156134d10b5983b1832f42627

View File

@ -4,3 +4,9 @@ C:\Users\root\source\repos\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibra
C:\Users\root\source\repos\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.csproj.CoreCompileInputs.cache C:\Users\root\source\repos\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.csproj.CoreCompileInputs.cache
C:\Users\root\source\repos\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.dll C:\Users\root\source\repos\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.dll
C:\Users\root\source\repos\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.pdb C:\Users\root\source\repos\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.pdb
C:\Users\root\source\SoftwareEngineering2\WindowsFormsApp01\ClassLibrary01\bin\Debug\ClassLibrary01.dll
C:\Users\root\source\SoftwareEngineering2\WindowsFormsApp01\ClassLibrary01\bin\Debug\ClassLibrary01.pdb
C:\Users\root\source\SoftwareEngineering2\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.csprojAssemblyReference.cache
C:\Users\root\source\SoftwareEngineering2\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.csproj.CoreCompileInputs.cache
C:\Users\root\source\SoftwareEngineering2\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.dll
C:\Users\root\source\SoftwareEngineering2\WindowsFormsApp01\ClassLibrary01\obj\Debug\ClassLibrary01.pdb

View File

@ -34,6 +34,10 @@
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.trackBar1 = new System.Windows.Forms.TrackBar(); this.trackBar1 = new System.Windows.Forms.TrackBar();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
@ -76,11 +80,16 @@
// //
// panel1 // panel1
// //
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.panel1.BackColor = System.Drawing.Color.DimGray; this.panel1.BackColor = System.Drawing.Color.DimGray;
this.panel1.Location = new System.Drawing.Point(264, 125); this.panel1.Location = new System.Drawing.Point(264, 125);
this.panel1.Name = "panel1"; this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(512, 256); this.panel1.Size = new System.Drawing.Size(512, 256);
this.panel1.TabIndex = 4; this.panel1.TabIndex = 4;
this.panel1.AutoSizeChanged += new System.EventHandler(this.Panel1_AutoSizeChanged);
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.Panel1_Paint); this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.Panel1_Paint);
// //
// trackBar1 // trackBar1
@ -95,13 +104,55 @@
this.trackBar1.Value = 1; this.trackBar1.Value = 1;
this.trackBar1.Scroll += new System.EventHandler(this.TrackBar1_Scroll); this.trackBar1.Scroll += new System.EventHandler(this.TrackBar1_Scroll);
// //
// button2
//
this.button2.Location = new System.Drawing.Point(24, 246);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 6;
this.button2.Text = "cat_slow";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.Button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(152, 246);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 7;
this.button3.Text = "cat_fast";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.Button3_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(170, 299);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 8;
this.label2.Text = "label2";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(43, 299);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 13);
this.label3.TabIndex = 9;
this.label3.Text = "label3";
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.trackBar1); this.Controls.Add(this.trackBar1);
this.Controls.Add(this.panel1); this.Controls.Add(this.panel1);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
@ -112,6 +163,7 @@
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1"; this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load); this.Load += new System.EventHandler(this.Form1_Load);
this.Resize += new System.EventHandler(this.Form1_Resize);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
@ -128,6 +180,10 @@
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TrackBar trackBar1; private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
} }
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -16,6 +17,8 @@ namespace WindowsFormsApp01
private int _number; private int _number;
private int _scale = 1; private int _scale = 1;
private int _x;
private int _y;
public int Number public int Number
{ {
@ -68,31 +71,47 @@ namespace WindowsFormsApp01
label1.Text = "Ergebnis: " + res.ToString(); label1.Text = "Ergebnis: " + res.ToString();
} }
private void Panel1_Paint(object sender, PaintEventArgs e) private void Panel1_Paint(object sender, PaintEventArgs e)
{ {
Graphics graphics = e.Graphics; Graphics graphics = e.Graphics;
Pen _pen = new ClassLibrary01.Class1().getPen();
using (var p = _pen)
{
//y axis //y axis
graphics.DrawLine(new Pen(Color.Black), 10, 10, 10, 246); graphics.DrawLine(p, 10, 10, 10, 246);
//x axis //x axis
graphics.DrawLine(new Pen(Color.Black), 10, 246, 502, 246); graphics.DrawLine(p, 10, 246, 502, 246);
//arrow y axis //arrow y axis
graphics.DrawLine(new Pen(Color.Black), 5, 15, 10, 10); graphics.DrawLine(p, 5, 15, 10, 10);
graphics.DrawLine(new Pen(Color.Black), 15, 15, 10, 10); graphics.DrawLine(p, 15, 15, 10, 10);
//arrow x axis //arrow x axis
graphics.DrawLine(new Pen(Color.Black), 498, 241, 502, 246); graphics.DrawLine(p, 498, 241, 502, 246);
graphics.DrawLine(new Pen(Color.Black), 498, 251, 502, 246); graphics.DrawLine(p, 498, 251, 502, 246);
}
Brush aBrush = (Brush) Brushes.Red; Brush aBrush = (Brush) Brushes.Red;
for (int i = 10; i < 502; i++) for (int i = 10; i < (502 ); i++)
{ {
int y = (int)( 246 - (((Math.Log(i) * 10) - 23) *_scale ) ); int y = (int)( 246 - (((Math.Log(i) * 10) - 23) *_scale ) );
@ -116,6 +135,69 @@ namespace WindowsFormsApp01
panel1.Refresh(); panel1.Refresh();
} }
private void Panel1_AutoSizeChanged(object sender, EventArgs e)
{
}
private void Form1_Resize(object sender, EventArgs e)
{
_x = panel1.Width;
_y = panel1.Height;
panel1.Invalidate();
}
private void Button2_Click(object sender, EventArgs e)
{
string s1 = "hello";
string s2 = "Offenburg";
string s3 = String.Empty;
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 50000; i++)
{
s3 = s3 + s1 + s2;
}
sw.Stop();
label3.Text = sw.ElapsedMilliseconds.ToString();
}
private void Button3_Click(object sender, EventArgs e)
{
string s1 = "hello";
string s2 = "Offenburg";
string s3 = String.Empty;
Stopwatch sw = new Stopwatch();
var sb = new StringBuilder();
sw.Start();
for (int i = 0; i < 50000; i++)
{
//s3 = s3 + s1 + s2;
sb.Append(s1);
sb.Append(s2);
}
sw.Stop();
label2.Text = sw.ElapsedMilliseconds.ToString();
}
} }
} }