Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
[Allgemein] -  C# vs Python
#6
Ja, bitte auch die weiteren Erklärung zeigen.

Zitat:Perfekt! Dann erkläre ich dir jetzt die dotnet CLI, typische Projektstruktur, wichtige Bibliotheken und wie man Python und C# kombiniert. Ich mache es Schritt für Schritt, praxisnah und verständlich für dich als Python-Programmierer.

1. dotnet CLI – die Kommandozeilen-Werkzeuge
Die dotnet CLI ist das zentrale Werkzeug für .NET-Entwicklung.
Vergleichbar mit:
  • Code:
    python
    /
    Code:
    pip
    /
    Code:
    venv
    in Python
  • Code:
    node
    /
    Code:
    npm
    in JavaScript

1.1. Wichtige Befehle
Befehl
Funktion
Beispiel
Code:
dotnet new console -n MeinProjekt
Neues Konsolenprojekt erstellen
Code:
dotnet new console -n TestApp
dotnet build
Projekt kompilieren
Code:
dotnet build
dotnet run
Projekt ausführen
Code:
dotnet run
dotnet add package <Paket>
NuGet-Paket installieren
Code:
dotnet add package Newtonsoft.Json
dotnet restore
Alle Pakete neu herunterladen
Code:
dotnet restore
dotnet clean
Build-Verzeichnisse löschen
Code:
dotnet clean
dotnet publish
App für Verteilung bauen
Code:
dotnet publish -c Release -r win-x64

2. Typische Projektstruktur
Ein einfaches Konsolenprojekt sieht so aus:
Code:
TestApp/

├─ TestApp.csproj     ← Projektdatei (.NET) enthält Paketreferenzen
├─ Program.cs         ← Hauptcode
├─ obj/               ← temporäre Build-Dateien
├─ bin/               ← kompilierte Programme
└─ README.md          ← optional
Program.cs Beispiel:
Code:
using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("Hallo Welt aus C#!");
    }
}

3. Wichtige Bibliotheken für Anfänger
3.1. JSON-Verarbeitung
Code:
dotnet add package Newtonsoft.Json
Beispiel:
Code:
using Newtonsoft.Json;
var person = new { Name = "Tom", Alter = 60 };
string json = JsonConvert.SerializeObject(person);
Console.WriteLine(json);
3.2. HTTP-Anfragen
Code:
dotnet add package System.Net.Http
Beispiel:
Code:
using System.Net.Http;
var client = new HttpClient();
var response = await client.GetStringAsync("https://example.com");
Console.WriteLine(response);
3.3. Datenbanken
  • MySQL:
    Code:
    MySql.Data

  • PostgreSQL:
    Code:
    Npgsql

  • SQLite:
    Code:
    Microsoft.Data.Sqlite

Installieren über NuGet:
Code:
dotnet add package Npgsql
3.4. GUI
  • WinForms: Windows-only, einfach
  • WPF: Windows, modern
  • MAUI: plattformübergreifend (Windows, Linux, macOS, Android, iOS)

4. Python & C# kombinieren
Es gibt Situationen, in denen du Python-Code weiter nutzen willst:
4.1. Python aus C# aufrufen
Code:
using System.Diagnostics;
Process.Start("python", "script.py");
→ Führt ein externes Python-Skript aus.
4.2. IronPython
  • Python-Interpreter direkt in .NET
  • Python-Code kann direkt C#-Objekte benutzen
  • Funktioniert gut für kleine Skripte
  • Beispiel:
Code:
using IronPython.Hosting;
var engine = Python.CreateEngine();
engine.Execute("print('Hallo aus Python!')");
4.3. Daten über JSON oder CSV austauschen
  • Python-Skript erzeugt JSON
  • C# liest JSON und verarbeitet es weiter
  • Sehr stabil und plattformübergreifend

5. Typische Anfängerprojekte
Hier ein paar Projektideen, die du leicht mit C# starten kannst:
Projekt
Python-Äquivalent
BemerkungKonsolen-Taschenrechner
Python-Konsolenprogramm
Perfekt zum Üben
Mini-Notizbuch (WinForms)
Python Tkinter
GUI-Einstieg
JSON-Reader / API-Client
Python Requests
Übung für NuGet + HTTP
CSV-Parser / Datenverarbeitung
Python Pandas
Übung für BCL + LINQ
Mini-Webserver (ASP.NET Core)
Python Flask
Einstieg in Webentwicklung

6. Zusammenfassung
  • dotnet CLI = alles wie pip + python + virtualenv in einem
  • Projektstruktur = csproj + Program.cs + bin/obj
  • NuGet = Paketmanager für Bibliotheken
  • CLR = Laufzeitumgebung wie Python-Interpreter
  • .NET vs .NET Framework = modern vs legacy
  • Python + C# = entweder über
    Code:
    Process.Start
    , IronPython oder Datenformate (JSON/CSV)

Wenn du willst, kann ich dir als Nächstes ein kleines Praxisprojekt bauen, das Python-Skript + C# GUI kombiniert, sodass du sofort siehst, wie beide Welten zusammenarbeiten.
Willst du, dass ich das erstelle?
Zitieren Return to top


Nachrichten in diesem Thema
C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden
RE: C# vs Python - von Joopi - Vor 3 Stunden

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste