将Linux C转换为C# [英] Convert a linux c to c#

查看:68
本文介绍了将Linux C转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将linux c转换为c#
在c linux中使用此代码.我想换成C#

我的c代码进入Linux,但是我想要c#:

Convert a linux c to c#
Hi this code in c linux . I want change to c#

My c code into Linux, but I want the c #:

<pre>struct coustomerid <br />
{<br />
Int id;<br />
}<br />
<br />
Void*customer(void*parametrs)<br />
{<br />
Struct customer*myid =(struct customertid*)parameters;<br />
Printf("%d",myid->id);<br />
}<br />
Int main()<br />
{<br />
Pthrad_t c1;<br />
Struct coustomerid cid1;<br />
cid1.id = 1;<br />
pthread_create (&c1,NULL,&customer,&cid1);<br />
}</pre><br />

推荐答案

这将是一个非常接近的等效项:

This would be a pretty close equivalent:

struct Customer
{
    public int Id { get; set; }
}

class Program
{
    static void Main()
    {
        Thread thread = new Thread(new ThreadStart(ThreadProc));
        thread.Start();
    }

    static void ThreadProc()
    {
        Customer customer = new Customer() { Id = 1 };
        ShowCustomer(customer);
    }

    static void ShowCustomer(Customer customer)
    {
        Console.WriteLine("Id : {0}", customer.Id);
    }
}



不过,这并不是一种非常.NET的方式.



It''s not a very .NET-ish way to do this though.


这里是另一种方式(将参数传递给线程).与我之前的示例相比,这更接近您的Linux代码.

Here''s an alternate way (where you pass the parameter to the thread). This is closer to your Linux code than my earlier example.

struct Customer
{
    public int Id { get; set; }
}

class Program
{
    static void Main()
    {
        Customer customer = new Customer() { Id = 1 };
        Thread thread = new Thread(new ParameterizedThreadStart(ShowCustomer));
        thread.Start(customer);
    }

    static void ShowCustomer(object param)
    {
        Customer customer = (Customer)param;
        Console.WriteLine("Id : {0}", customer.Id);
    }
}


以上代码的目标是什么?是创建并运行输出到控制台的线程吗?
What is the goal of the above code? Is it to create and run a thread that outputs to the console?


这篇关于将Linux C转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆