Docly

Your first project

Estimated reading: 2 minutes 0 views

مقدمة حول إنشاء مشروع C # الأول باستخدام .NET

مرحبًا بكم في هذا الدرس التمهيدي حول إنشاء مشروع C # الأول باستخدام .NET! سوف نتعرف علي إعداد بيئة التطوير الخاصة بك ، وإنشاء مشروع C # جديد ، وكتابة بعض التعليمات البرمجية الأساسية . بنهاية هذا الدرس ، سيكون لديك أساس متين لإنشاء تطبيقات C # أكثر تعقيدًا باستخدام .NET framework.

Prerequisites

قبل أن نبدأ ، تأكد من تثبيت ما يلي على نظامك:

  1. .NET SDK – Download the latest version of the .NET SDK for your operating system.
  2. Visual Studio Code – A lightweight, yet powerful source code editor with great support for C# and .NET development.
  3. [C# extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) – This extension provides rich support for C# development in Visual Studio Code.

Creating a New C# Project

Once you have all the prerequisites installed, open your terminal (or command prompt on Windows) and follow these steps to create a new C# project:

  1. Create a new directory for your project and navigate to it: mkdir MyFirstCSharpProject cd MyFirstCSharpProject
  2. Run the dotnet new command to create a new console application project: dotnet new console This command will generate a new C# console application with a single file named Program.cs.
  3. Open the project in Visual Studio Code: code . This command will open the current directory in Visual Studio Code

كتابة أول كود C #

In Visual Studio Code, you should see the Program.cs file in the file explorer. This file contains the main class and method for our console application.

  1. Open Program.cs and take a look at the code:
using System;

namespace MyFirstCSharpProject
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
The Main method is the entry point of our console application, and it's where our program starts executing. In this example, it simply writes "Hello World!" to the console.

Modify the code to greet the user with their name:

using System;
namespace MyFirstCSharpProject
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter your name: ");
            string name = Console.ReadLine();
            Console.WriteLine($"Hello, {name}!");
        }
    }
}

تشغيل المشروع

الآن بعد أن كتبنا بعض التعليمات البرمجية ، دعنا نقوم بتشغيل المشروع:

    In Visual Studio Code, open the terminal (View > Terminal).

    Run the following command to build and execute the program:

    dotnet run

    You should see the "Enter your name:" prompt. Enter your name, and the program will greet you with a personalized message.

لقد قمت بنشاء مشروع C# الأول بنجاح! لقد كتبت بعض التعليمات البرمجية الأساسية، وهذا يعني أنه يمكنك الآن مواصلة استكشاف مزيد من الميزات والمكتبات المتاحة في إطار .NET لإنشاء تطبيقات أكثر تعقيداً. أتمنى لك التوفيق في رحلتك البرمجية!

.

Leave a Comment

Share this Doc
CONTENTS