0

I consider this as a continuation of what I've learned from my two previous threads. Instead of Javascript I will be using pure C#.

I have a class with 3 parameters in it, and I am creating a variable which is a result of deserialization to class type

var param = js.Deserialize<ClassName>(jqData.Params);

Based on what I've learned from my first thread, it stores values based on inputs I've made within 3 textboxes that I have.

For our purposes, let's assume I only placed input in a second textbox out of three, so the values would be null, "abc", null.

Now, I got some very good suggestions from my second post, which I want to implement.

I want to create an array of objects, WITHOUT initializing, since those objects already hold values, reduce array down to 1 element based on criteria from that excellent post, and then proceed with my validation logic.

However, I am struggling with declaring array part. From what I saw here in SO, most of threads are talking about declaring and initializing those elements. I don't need it.

What I need is to declare an array, which would have class elements in it, something like array = [param.elem1, param.elem2, param.elem3], and when I run a code, it will return [null, "abc", null].

Can you please point me in the right direction on how to properly declare such array?

1 Answer 1

1

Your idea was close to how this can be handled. Just change your array = [param.elem1, param.elem2, param.elem3] to:

var myArray = new object[] { param.elem1, param.elem2, param.elem3 };

If you know the type of param.elem1/2/3, you can use the specific type (e.g. string[] instead of object[]).

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

2 Comments

I will test it out tomorrow morning and tell you the results.
Yep, looks like exactly what I need, thank you very much!

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.