1

I have written a piece of code in PHP which basically looks like this:

$order = array( 
'0' => array( 
'user_order_sn' => '123', 
'country' => 'some', 
'firstname' => '123', 
'lastname' => '123', 
'addressline1' => 'AFDAFAF', 
'addressline2' => '', 
'shipping_method' => '123', 
'tel' => '551245', 
'state' => '4444', 
'city' => '55r', 
'zip' => '1004451', 
'order_remark' => 'test', 
'order_platforms' => 3, 
'original_order_id' => '7126216', 
'original_account' => '51251251', 
'original_order_amount' => 2.57, 
'goods_info' => array( 0 => array( 'goods_sn' => '6544321', 'goods_number' => 4
)
),
),
);

So as you can see order variable is array of arrays which contains a variable goods_info which also array of array inside it.

I would like to replicate this in c#. I suspect I need to use jagged arrays here, but I'm not 100% sure how to do that. I created a class for starters which contain all the info above:

  public class CreateOrderDataRequest
    {
        public string user_order_sn { get; set; }
        public string country { get; set; }

        public string firstname { get; set; }
        public string lastname { get; set; }

        public string addressline1 { get; set; }

        public string addressline2 { get; set; }
        public string shipping_method { get; set; }
        public string tel { get; set; }
        public string state { get; set; }
        public string city { get; set; }
        public string zip { get; set; }

        public string order_remark { get; set; }
        public string order_platforms { get; set; }
        public string original_order_id { get; set; }

        public string original_account { get; set; }
        public string original_order_amount { get; set; }
    }

Can someone help me out to finish this ? :)

P.S. I haven't finished the goods_info part because I'm not sure how to do that ...

1
  • Anyone guys ? =) Commented Mar 26, 2017 at 12:49

1 Answer 1

1

Create a new class called GoodsInfo. Then add a List<GoodsInfo> to your CreateOrderDataRequest.

public class Order
{
    public class Order()
    {
        Requests = new List<OrderDataRequest>();
    }

    public List<OrderDataRequest> Requests { get; set; }
    //OR
    public OrderDataRequest[] Requests { get; set; }
}

public class OrderDataRequest
{
    public OrderDataRequest()
    {
        GoodsInfos = new List<GoodsInfo>();
    }

    public string user_order_sn { get; set; }
    .
    .
    .
    public List<GoodsInfo> GoodsInfos {get; set;}
    //OR
    public GoodsInfo[] GoodsInfo { get; set; }
}

public class GoodsInfo
{
    public string goods_sn { get; set; }
    public string good_number { get; set; }
}

Edit: I updated the code to add the full class structure. Additionally, I added initialization of the Lists in a constructor which you may need to do depending on how you are creating your objects.

Sign up to request clarification or add additional context in comments.

5 Comments

Hey thx alot for this... What about the entire order parameter in C# ? It is array of arrays as well here... How could I replicate that part in c# ?
Same thing, just add a class that contains a List<CreateOrderDataRequest>. I can edit my answer with an example, if you would like?
Ninja yes please I would really be grateful for that! =) I haven't worked much with C# so I'm not exactly sure =/
Usually when converting PHP to C#, you can think of a PHP key value array as a C# class with properties.
Ninja thx a lot ... Yeah I understand it much much better now. It's quite similar after all =D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.