DEV Community

Nosirbek
Nosirbek

Posted on • Edited on

2 1

C# Action

Program.cs

using ActionTask;

public class Program
{
    // Action yasab IEnumurable ga Extension qo'shishga misol
    public static void Main(string[] args)
    {
        var sonlar = new int[] {1,2,3,4,5};

        sonlar.Print(System.Console.WriteLine);


        var sonlarString = new [] {"1","2","3","4"};

        sonlarString.PrintF(File.WriteAllText);
    }
}
Enter fullscreen mode Exit fullscreen mode

LinqExtansions.cs

namespace ActionTask;

public static class LinqExtansions
{

    // Action yasab IEnumurable ga Extension qo'shishga misol
    public static void Action<T1>(T1 arg1){ }

    public static void Print<T1>(this IEnumerable<T1> toplam, Action<T1> callback)
    { 
        foreach(var item in toplam)
        {
            callback?.Invoke(item);
        }
    }


    // File -----
    public static void Action<T1,T2>(T1 arg1, T2 arg2){ }

    public static void PrintF<T1>(this IEnumerable<T1> toplam, Action<string, T1> callback)
    {
        foreach(var item in toplam)
        {
            callback.Invoke($"{Guid.NewGuid()}.txt",item);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Result

To’plamdagi har bir element uchun alohida FILE yaratadi

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay