Skip to content

Commit

Permalink
Collections: Array, List<>, Dictionary<>
Browse files Browse the repository at this point in the history
  • Loading branch information
theWornOut committed Mar 11, 2018
1 parent 9cac626 commit 2165f28
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 5 deletions.
10 changes: 5 additions & 5 deletions CSharpCourse.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Constructors", "Constructor
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReferenceAndValueType", "ReferenceAndValueType\ReferenceAndValueType.csproj", "{19241FEF-286C-45C9-B938-5023EDF42E4D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Collections", "Collections\Collections.csproj", "{A33AE829-B238-4A33-900B-360E48FC8B93}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Collections", "Collections\Collections.csproj", "{B129E0A5-754B-4F8A-A68C-6205EB07F830}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -119,10 +119,10 @@ Global
{19241FEF-286C-45C9-B938-5023EDF42E4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19241FEF-286C-45C9-B938-5023EDF42E4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19241FEF-286C-45C9-B938-5023EDF42E4D}.Release|Any CPU.Build.0 = Release|Any CPU
{A33AE829-B238-4A33-900B-360E48FC8B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A33AE829-B238-4A33-900B-360E48FC8B93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A33AE829-B238-4A33-900B-360E48FC8B93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A33AE829-B238-4A33-900B-360E48FC8B93}.Release|Any CPU.Build.0 = Release|Any CPU
{B129E0A5-754B-4F8A-A68C-6205EB07F830}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B129E0A5-754B-4F8A-A68C-6205EB07F830}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B129E0A5-754B-4F8A-A68C-6205EB07F830}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B129E0A5-754B-4F8A-A68C-6205EB07F830}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions Collections/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
46 changes: 46 additions & 0 deletions Collections/Collections.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<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')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B129E0A5-754B-4F8A-A68C-6205EB07F830}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Collections</RootNamespace>
<AssemblyName>Collections</AssemblyName>
<TargetFrameworkVersion>v4.6.1</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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
101 changes: 101 additions & 0 deletions Collections/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
namespace Collections
{
using System;
using System.Collections;
using System.Collections.Generic;

internal class Program
{
private static void Main(string[] args)
{
ArrayListMethod();

ListMethod();

Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("book", "kitap");
dictionary.Add("table", "tablo");
dictionary.Add("computer", "bilgisayar");

foreach (var item in dictionary)
{
Console.WriteLine(item);
Console.WriteLine(item.Key);
Console.WriteLine(item.Value);
}

var dictionaryCount = dictionary.Count;
var containsKey = dictionary.ContainsKey("glass");
var containsValue = dictionary.ContainsValue("phone");

Console.ReadLine();
}

private static void ListMethod()
{
List<string> cities = new List<string> { "Istanbul" };
foreach (var city in cities)
{
Console.WriteLine(city);
}

List<Customer> customers = new List<Customer>
{
new Customer {Id = 1, Name = "Ekrem"},
new Customer {Id = 2, Name = "Alpay"}
};

var customer = new Customer
{
Id = 3,
Name = "Emre"
};
customers.Add(customer);
customers.AddRange(new Customer[2]
{
new Customer
{
Id =4, Name = "Ali"
},
new Customer
{
Id = 5,Name = "Ezgi"
}
});

var count = customers.Count;
var contains = customers.Contains(customer);
var indexOf = customers.IndexOf(customer);
var lastIndexOf = customers.LastIndexOf(customer);
customers.Insert(0, customer);
customers.Remove(customer);
customers.RemoveAll(c => c.Name == "Istanbul");

foreach (var item in customers)
{
Console.WriteLine(item.Name);
}
}

private static void ArrayListMethod()
{
ArrayList cities = new ArrayList();
cities.Add("Istanbul");
cities.Add("Ankara");
cities.Add("Izmir");
cities.Add(1);
cities.Add(true);

foreach (var city in cities)
{
Console.WriteLine(city);
}
}
}

class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}
}
36 changes: 36 additions & 0 deletions Collections/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("Collections")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Collections")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("b129e0a5-754b-4f8a-a68c-6205eb07f830")]

// 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")]

0 comments on commit 2165f28

Please sign in to comment.