Commit 16e46dd0 authored by Uwe Wienkop's avatar Uwe Wienkop

Call by reference

parent 82839273
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<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" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="App.config" />
<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 Name="AfterBuild">
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _10CallByReference
class Program
static void IncrByValue(int x)
{ // Call by Value: Wert wird kopiert
x = x + 1;
Console.WriteLine($"x in Incr {x}");
static void IncrByRef(ref int x, out int y)
{ // Ref: Es ist sichergestellt, dass die Ref-Var. einen initialisierten Wert besitzt
// Out: Es ist nicht sichergestellt, dass die out-Var einen init. Wert besitzt
// ABER: Es wird in der Funktion sichergestellt, dass der out-Var ein
// Wert zugewiesen wird, analog zum return
x = x + 1;
y = x * 2;
Console.WriteLine($"x in Incr-By-Ref {x}, y in Main {y}");
//static double Gps2Kart(double Laengengrad, double Breitengrad,
// out double x, out double y)
static void IncrArrayByValue(int[] f)
for (int i = 0; i < f.Length; i++)
static void IncrArrayByRef(ref int[] f)
f = new int[] { 100, 200, 300, 400, 500, 600, 700, 800 };
static void Main(string[] args)
int x = 10;
int a = 20;
int[] feld = { 10, 20, 30, 40 };
IncrByValue(x + 1); // Bei der by-value-Übergabe sind auch arithm. Ausdrücke erlaubt
IncrByRef(ref x, out a);
// IncrByRef(ref x + 1, out a); // Bei der by-ref-Übergabe sind nur Variablen erlaubt
// keine Konstanten, keine arithm. Ausdrücke!
// Übergabe per ref: Variable muss vorher intialisiert worden sein
// Übergabe per out: Variable muss vorher nicht init. werden
Console.WriteLine($"x in Main {x}, a in Main {a}");
foreach (int item in feld)
IncrArrayByRef(ref feld);
foreach (int item in feld)
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("10CallByReference")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("10CallByReference")]
[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("1a720d7e-a300-4351-9052-b774416a1be8")]
// 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("")]
[assembly: AssemblyFileVersion("")]
......@@ -79,6 +79,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "10JaggedArrays", "10JaggedA
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "10WortweiseZerlegung", "10WortweiseZerlegung\10WortweiseZerlegung.csproj", "{375DCCFF-AD56-4BD7-B382-CB3DCBA7B79F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "10CallByReference", "10CallByReference\10CallByReference.csproj", "{1A720D7E-A300-4351-9052-B774416A1BE8}"
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -225,6 +227,10 @@ Global
{375DCCFF-AD56-4BD7-B382-CB3DCBA7B79F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{375DCCFF-AD56-4BD7-B382-CB3DCBA7B79F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{375DCCFF-AD56-4BD7-B382-CB3DCBA7B79F}.Release|Any CPU.Build.0 = Release|Any CPU
{1A720D7E-A300-4351-9052-B774416A1BE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A720D7E-A300-4351-9052-B774416A1BE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A720D7E-A300-4351-9052-B774416A1BE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A720D7E-A300-4351-9052-B774416A1BE8}.Release|Any CPU.Build.0 = Release|Any CPU
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