Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 #:

struct coustomerid 
{
Int id;
}

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

This would be a pretty close equivalent:

C#
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);
    }
}


It's not a very .NET-ish way to do this though.
 
Share this answer
 
Comments
Abhinav S 13-Apr-11 13:56pm    
Nice. 5.
Here's an alternate way (where you pass the parameter to the thread). This is closer to your Linux code than my earlier example.

C#
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);
    }
}
 
Share this answer
 
Comments
esmailian 14-Apr-11 7:46am    
OK this code is closer to the original source
What is the goal of the above code? Is it to create and run a thread that outputs to the console?
 
Share this answer
 
Comments
esmailian 13-Apr-11 13:44pm    
This part of the source code is a Barber problem in this part I just had trouble here, I wrote a separate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900