Commit 1aa00e23 authored by Uwe Wienkop's avatar Uwe Wienkop

Properties, static-Var

parent 7239ba35
......@@ -8,27 +8,65 @@ namespace _07IntroKlassen
{
class Person
{
public string Name, Vorname, Anschrift;
string name, vorname, anschrift;
int alter;
public Person(string Name, string Vorname, int Alter=1, string Anschrift="")
{
this.name = Name;
this.vorname = Vorname;
this.alter = Alter;
this.anschrift = Anschrift;
}
//public static void Ausgeben(Person p)
//{
// Console.WriteLine($"{p.Vorname} {p.Name}");
//}
public void Ausgeben()
{
Console.WriteLine($"{Vorname} {Name}");
Console.WriteLine($"{vorname} {name}");
}
public string getName()
{
return name;
}
public void setName(string value)
{
name = value;
}
public string Name
{
get { return name; }
set { name = value; }
}
public int Alter
{
get { return alter; }
set
{
if (value >= 0)
alter = value;
else
throw new ArgumentOutOfRangeException("Für das Alter sind nur positive Werte erlaubt");
}
}
}
// ==================================================
class Program
{
static void Main(string[] args)
{
Person anton = new Person();
anton.Name = "Meier";
anton.Vorname = "Anton";
Person anton = new Person("Meier","Anton",20,"Holzweg 12");
//anton.Name = "Meier";
//anton.Vorname = "Anton";
Person berta = new Person();
berta.Vorname = "Berta";
berta.Name = "Huber";
Person berta = new Person("Huber", "Berta", 23); // "Irrweg 13");
berta.setName(berta.getName() + "-Schulz");
Console.WriteLine(berta.getName());
berta.Name = berta.Name + "-Schulz";
Console.WriteLine(berta.Name);
berta.Alter++;
// berta.Alter = berta.Alter + 1;
Person[] pfeld = new Person[2];
pfeld[0] = anton;
......@@ -40,6 +78,7 @@ namespace _07IntroKlassen
//Person.Ausgeben(p);
p.Ausgeben();
}
berta.Alter = -10;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C2DC77D3-C340-4C84-A180-21655CF5C227}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_08Handy</RootNamespace>
<AssemblyName>08Handy</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Handy.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _08Handy
{
class Handy
{
static int klassenseriennummer = 1;
// static = Diese Var. gibt es nur EINMAL für die Klasse
string telNr;
int serNr;
// nicht-static = Diese Datenfelder gibt es pro Handyobjekt
public Handy(string TelNr)
{
telNr = TelNr;
serNr = klassenseriennummer;
klassenseriennummer++;
}
public void Ausgeben()
{
Console.WriteLine($"Handy: {telNr}, Seriennummer: {serNr}");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _08Handy
{
class Program
{
static void Main(string[] args)
{
Handy h1 = new Handy("4711");
Handy h2 = new Handy("4712");
h1.Ausgeben();
h2.Ausgeben();
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("08Handy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("08Handy")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c2dc77d3-c340-4c84-a180-21655cf5c227")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
......@@ -62,6 +62,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "07ZweidimFelder", "07Zweidi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "07IntroKlassen", "07IntroKlassen\07IntroKlassen.csproj", "{232DF40A-8C82-408A-8E59-3AA60F2A0DF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "08Handy", "08Handy\08Handy.csproj", "{C2DC77D3-C340-4C84-A180-21655CF5C227}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -176,6 +178,10 @@ Global
{232DF40A-8C82-408A-8E59-3AA60F2A0DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{232DF40A-8C82-408A-8E59-3AA60F2A0DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{232DF40A-8C82-408A-8E59-3AA60F2A0DF8}.Release|Any CPU.Build.0 = Release|Any CPU
{C2DC77D3-C340-4C84-A180-21655CF5C227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2DC77D3-C340-4C84-A180-21655CF5C227}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2DC77D3-C340-4C84-A180-21655CF5C227}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2DC77D3-C340-4C84-A180-21655CF5C227}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment