Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am creating a JSON Object.
I want to achieve the below
I would want to make the name of the variable "item_1" dynamic.
So if there 3 items in the loop.
I should create item_1, item_2, item_3 etc
dynamic extension = new JObject();
dynamic item_1 = new JObject();
item_1.id = "00000000-0000-7000-0000-0000000c74c7";
item_1.risk_action = "Bind";
extension.Add(item_1);
How can i achieve the above in a for loop and create variable names dynamically and add it to the main json object
Thanks
C# is strongly typed so you can't create variables dynamically.
One way to solve it, is to use an array, or you could use a dictionary
look at:
https://learn.microsoft.com/de-de/dotnet/api/system.collections.generic.dictionary-2?view=net-5.0
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
In my project; I have so many json file from web. And inside json file have campaign datas. But that data numbers is always changing. For example in first json it have 5 data and other json have 15. So I need create labels for that datas. For example if in the json file have 5 campaign data , i need create 5. İf it have 10 then i need create 10. Like this. So how can i make it ? I input json files and its works correctly i just need learn how can i create , position N label in xamarin ? Thanks for your help! <3
just create them and add them to some layout container, like this
var stack = new StackLayout();
foreach(var l in LabelData())
{
stack.Children.Add(new Label { Text = l.SomeProperty });
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've encountered sometimes code like this and I am kind of new to programming. I want to find out what's the meaning behind those objects or data type enclosed in parenthesis.
(int)
(datagridview)
(form)
If you see something like this it's called a cast. It's used to explicitly convert a data type to another data type.
double pi = 3.14159;
int my_int = (int)pi;
See this description on casting for more details.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am making a game where there are squares (sectors) generated to make a path for a ball to go. There are two types of sectors: Sector and Presector. They are all put into a list of type Sector. How would I check to see if a specific sector in that list was actually a Presector before it was put in?
BTW: Presector is a child class of Sector.
I looked all over the place and couldn't find anything. The as keyword isn't working for me, and Type.IsAssignableFrom isn't either. EDIT: is will not work either, since that just checks if an object is that type.
SAMPLE CODE TIME!
List<Sector> sectors = new List<Sector>();
sectors.Add(new Sector());
sectors.Add(new Presector());
Now, we have a list full of two sectors. The second one was casted. How do I find that out using code?
if (objectFromList is Presector)
// Code here..
List<Sector> sectors = new List<Sector>();
sectors.Add(new Sector());
sectors.Add(new Presector());
sectors.Add(new Sector());
Presector ps = new Presector();
sectors.Add(ps);
// this returns an array with one element
var x = sectors.OfType<Presector>().ToArray();
// this returns true (the second element IS a Presector)
var hasPresector = sectors.Any(s => s is Presector);
// this returns true (the presector is present in the list)
var containsPs = sectors.Contains(ps);
What's the problem with the 'is' keyword?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Is it possible to add numbers to the total value of an int cell instead of set its value? Correctly I'm using a list and I and things are getting weird.. the list is <int> list and its value is jumping into random numbers without any reason. I think that changing the count type (from list into int) will solve it. (c#. visual studio 2013).
Doesn't look so hard to me...?
int variable = 10; // start with 10 points
variable++; // add 1
variable += 3 // add 3
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to write some property item to image. Though I could not do it. But I can edit any currently added property. So I want to know is there are any property item I can use for my purpose? Here are some Id I am getting:
Id:271
type 2
Id:272
type:2
Id:274
type:3
Id:282
type:5
Id:283
type:5
Id:296
type:3
Id:306
type:2
....
etc.
My question is can I use any of the currently present property?
Sounds simple i think
<img id="myimage" data-id="data you want to pass"/>
if you want to add attribute from c# then
ddLedger.Attributes.Add('data-id','yourvalue');
So you want to access this property at backend c# then
string aa=myimage.attributes("data-id");
in string aa you will get your data....
and in jquery
$('#myimage').attr('data-id');
Now if you want to add it at run time then like this
$('#myimage').attr('data-id','your id added');
Demo
Check this url for more details
https://stackoverflow.com/a/1735239/2630817
I hope this will help you....:)