[Yandex Cloud documentation](../../../index.md) > [Yandex Cloud Functions](../../index.md) > [Getting started](../index.md) > [Creating a function](index.md) > .NET Core

# Creating a function in .NET Core

Create and run a user welcome [function](../../concepts/function.md) in .NET Core.

## Getting started {#before-begin}

[Create a folder](../../../resource-manager/operations/folder/create.md) in Yandex Cloud.

## Create a function {#create-func}

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), select the folder where you want to create a function.
    1. Navigate to **Cloud Functions**.
    1. Click **Create function**.
    1. Enter the function name: `dotnet-function`.
    1. Click **Create**.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To create a function, run this command:

    ```bash
    yc serverless function create --name=dotnet-function
    ```

    Result:

    ```text
    id: b09bhaokchn9********
    folder_id: aoek49ghmknn********
    created_at: "2019-06-14T10:03:37.475Z"
    name: dotnet-function
    log_group_id: eolm8aoq9vcp********
    http_invoke_url: https://functions.yandexcloud.net/b09bhaokchn9********
    status: ACTIVE
    ```

- API {#api}

    You can create a function using the [create](../../functions/api-ref/Function/create.md) API method.


{% endlist %}

## Create the first version of your function {#create-first-version}

To create a function [version](../../concepts/function.md#version), you can use one of the [code upload formats](../../concepts/function.md#upload). This example uses a ZIP archive.

{% note warning %}

Use Object Storage to [upload](../../../storage/operations/objects/upload.md) files larger than 3.5 MB. For more information about limits, see [Quotas and limits in Cloud Functions](../../concepts/limits.md).

{% endnote %}

### Create a ZIP archive with the function code {#create-zip}

1. Save the following code to a file named `Handler.cs`:

    ```csharp
    using System;
    using System.Collections.Generic;

    namespace Function;

    public class Request
    {
        public Dictionary<string, string> queryStringParameters { get; set; }
    }

    public class Response
    {
        public Response(int statusCode, Dictionary<string, string> headers, bool isBase64Encoded, string body)
        {
            StatusCode = statusCode;
            Headers = headers;
            IsBase64Encoded = isBase64Encoded;
            Body = body;
        }

        public int StatusCode { get; set; }
        public Dictionary<string, string> Headers { get; set; }
        public bool IsBase64Encoded { get; set; }
        public string Body { get; set; }
    }

    public class Handler
    {
        public Response FunctionHandler(Request request)
        {
            var headers = new Dictionary<string, string>();
            headers.Add("Content-Type", "text/plain");

            string name = request.queryStringParameters["name"];
            return new Response(200, headers, false, string.Format("Hello, {0}!", name));
        }
    }
    ```

1. Add `Handler.cs` to the `hello-dotnet.zip` archive.

    {% note info %}
    
    If you use the Finder context menu to create a ZIP archive on macOS, the system automatically adds the `__MACOSX` system directory to the archive. This directory may cause errors when you build functions. To delete this directory from your ZIP archive, use the command line to navigate to the folder containing the archive and run this command:
    
    ```bash
    zip -d <archive_name>.zip "__MACOSX/*"
    ```
    
    {% endnote %}

### Create a function version {#create-version}

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), navigate to the folder containing the function.
    1. Navigate to **Cloud Functions**.
    1. Select the `dotnet-function` function.
    1. Under **Last version**, click **Сreate in editor**.
    1. Select the `.NET 8.0` runtime.
    1. Disable **Add files with code examples** and click **Continue**.
    1. Configure the version:
        * **Code source**: `ZIP archive`.
        * **File**: Attach `hello-dotnet.zip`.
        * **Entry point**: `Function.Handler`.
        * **Timeout**: `3`.
        * **Memory**: `128 MB`.
        * **Service account**: `Not selected`.
    1. Click **Save changes**.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To create a function version, run this command:

    ```bash
    yc serverless function version create \
      --function-name=dotnet-function \
      --runtime dotnet8.0 \
      --entrypoint Function.Handler \
      --memory 128m \
      --execution-timeout 3s \
      --source-path ./hello-dotnet.zip
    ```

    Where:

    * `--function-name`: Name of the function whose version you want to create.
    * `--runtime`: Runtime environment.
    * `--entrypoint`: Entry point.
    * `--memory`: Amount of RAM.
    * `--execution-timeout`: Maximum function execution time before timeout.
    * `--source-path`: ZIP archive with the function code and required dependencies.

    Result:

    ```text
    done (1s)
    id: d4evvn8obisa********
    function_id: d4elpv8pft63********
    created_at: "2020-08-01T19:09:19.531Z"
    runtime: dotnet8.0
    entrypoint: Function.Handler
    resources:
        memory: "134217728"
    execution_timeout: 3s
    image_size: "4096"
    status: ACTIVE
    tags:
    - $latest
    log_group_id: ckg3qh8h363p********
    ```

- API {#api}

    You can create a function version using the [createVersion](../../functions/api-ref/Function/createVersion.md) API method.


{% endlist %}

## Invoke the function {#invoke}

{% note info %}

To allow any user to invoke your function, [make it public](../../operations/function/function-public.md). For more information about access permissions, see [Access management in Cloud Functions](../../security/index.md).

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), navigate to the folder containing the function.
    1. Navigate to **Cloud Functions**.
    1. Select the function.
    1. Navigate to the ![CirclePlay](../../../_assets/console-icons/circle-play.svg) **Testing** tab.
    1. In the **Version tag** field, specify `$latest` to invoke the latest function version.
    1. In the **Payload template** field, select `No template`.
    1. In the **Payload** field, enter:
       ```
       {"queryStringParameters": {"name": "Username"}}
       ```
    1. Click ![PlayFill](../../../_assets/console-icons/play-fill.svg) **Run test**.
    1. You will see the test status under **Test result** in the **Function status** field. **Note** that the maximum function execution time before [timeout](../../operations/function/version-manage.md), including first call initialization, is ten minutes.
    1. You will see the function execution result in the **Function output** field:
       ```
       {
         "statusCode": 200,
         "headers": {
           "Content-Type": "text/plain"
         },
         "isBase64Encoded": false,
         "body": "Hello, Username!"
       }
       ```

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To invoke a function, run this command:

    ```
    yc serverless function invoke <function_ID> -d '{"queryStringParameters": {"name": "Username"}}'
    ```

    Result:

    ```
    {"statusCode":200,"headers":{"Content-Type":"text/plain"},"isBase64Encoded":false,"body":"Hello, Username!"}
    ```

    The function version with the `$latest` tag is invoked by default.

- HTTPS {#https}

	You can find the function invocation link on the **Overview** tab, in the **Link to invoke** field.

	For security reasons, you can only invoke a function via HTTPS. Invoke it as a regular HTTP request by pasting the link into the browser address bar and adding the `name` parameter to the URL:

	```
	https://functions.yandexcloud.net/<function_ID>?name=Username
	```

	The following response will appear on the page:

	```
	Hello, Username!
	```


{% endlist %}

## What's next {#what-is-next}

- To learn more about the function structure required for different invocation methods (HTTP and CLI), see [Invoking a function in Cloud Functions](../../concepts/function-invoke.md).
- Read about [service concepts](../../concepts/index.md).
- Check out our [step-by-step guides](../../operations/index.md) to learn what you can do with functions and their versions.