Questions tagged [dynamic]

Dynamic is a widely used term that, in general, describes a decision made by the program at run-time rather than at compile time.

Programs that perform some common tasks based on program inputs in contrast with programs that predetermine the task beforehand. Dynamic is often used to mean:

  • The dynamic keyword
  • using JavaScript to manipulate web pages in the browser.
  • have features that allow the of a variable to be bound at run-time.
  • Program generated content, especially content in contrast with web pages created by a person and stored on disk, ready to serve.
27209 questions
126
votes
34 answers

How can I create unique IDs with JavaScript?

I have a form where a user can add multiple select boxes for multiple cities. The problem is that each newly generated select box needs to have a unique id. Can this be done in JavaScript? Here is the part of the form for selecting cities. Also note…
JamesTBennett
  • 2,091
  • 6
  • 19
  • 22
126
votes
19 answers

Java dynamic array sizes?

I have a class - XClass, that I want to load into an array of XClasses: XClass myClass[] = new XClass[10]; myclass[0] = new XClass(); myclass[9] = new XClass(); However, I don't know if I will need 10, 8 or 12 classes or any other number for that…
Paul
  • 1,335
  • 3
  • 10
  • 5
122
votes
7 answers

Variable length (Dynamic) Arrays in Java

I was wondering how to initialise an integer array such that it's size and values change through out the execution of my program, any suggestions?
Mohammad Sepahvand
  • 17,364
  • 22
  • 81
  • 122
119
votes
5 answers

Javascript dynamically invoke object method from string

Can I dynamically call an object method having the method name as a string? I would imagine it like this: var FooClass = function() { this.smile = function() {}; } var method = "smile"; var foo = new FooClass(); // I want to run smile on the…
Mikulas Dite
  • 7,790
  • 9
  • 59
  • 99
119
votes
9 answers

Dynamically import a method in a file, from a string

I have a string, say: abc.def.ghi.jkl.myfile.mymethod. How do I dynamically import mymethod? Here is how I went about it: def get_method_from_file(full_path): if len(full_path) == 1: return map(__import__,[full_path[0]])[0] return…
lprsd
  • 84,407
  • 47
  • 135
  • 168
116
votes
7 answers

Dynamically set local variable

How do you dynamically set local variable in Python (where the variable name is dynamic)?
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
116
votes
8 answers

Is there a best practice for generating html with javascript

I'm calling a web service that returns an array of objects in JSON. I want to take those objects and populate a div with HTML. Let's say each object contains a url and a name. If I wanted to generate the following HTML for each object:
ckarbass
  • 3,651
  • 7
  • 34
  • 43
116
votes
15 answers

Difference between "var" and "dynamic" type in Dart?

According to this article: As you might know, dynamic (as it is now called) is the stand-in type when a static type annotation is not provided. So, what is the difference between dynamic and var? When to use?
Gero
  • 12,993
  • 25
  • 65
  • 106
115
votes
23 answers

Declare an empty two-dimensional array in Javascript?

I want to create a two dimensional array in Javascript where I'm going to store coordinates (x,y). I don't know yet how many pairs of coordinates I will have because they will be dynamically generated by user input. Example of pre-defined 2d…
Zannix
  • 1,473
  • 3
  • 16
  • 26
114
votes
5 answers

How to call methods dynamically based on their name?

How can I call a method dynamically when its name is contained in a string variable? For example: class MyClass def foo; end def bar; end end obj = MyClass.new str = get_data_from_user # e.g. `gets`, `params`, DB access, etc. str #=> "foo" #…
user502052
  • 14,803
  • 30
  • 109
  • 188
113
votes
3 answers

Dynamically Add C# Properties at Runtime

I know there are some questions that address this, but the answers usually follow along the lines of recommending a Dictionary or Collection of parameters, which doesn't work in my situation. I am using a library that works through reflection to do…
Paul Grimshaw
  • 19,894
  • 6
  • 40
  • 59
112
votes
5 answers

dynamic does not contain a definition for a property from a project reference

I am getting an error that says: 'object' does not contain a definition for 'Title' all the code is also on github I have a ConsoleApplication1 that looks like this namespace ConsoleApplication1 { class Program { static void…
eiu165
  • 6,101
  • 10
  • 41
  • 59
110
votes
3 answers

Why does the C# compiler not fault code where a static method calls an instance method?

The following code has a static method, Foo(), calling an instance method, Bar(): public sealed class Example { int count; public static void Foo( dynamic x ) { Bar(x); } void Bar( dynamic x ) { count++; …
Mike Scott
  • 12,274
  • 8
  • 40
  • 53
104
votes
5 answers

Dynamic SQL - EXEC(@SQL) versus EXEC SP_EXECUTESQL(@SQL)

What are the real world pros and cons of executing a dynamic SQL command in a stored procedure in SQL Server using EXEC (@SQL) versus EXEC SP_EXECUTESQL @SQL ?
Ash Machine
  • 9,601
  • 11
  • 45
  • 52
103
votes
3 answers

Extension method and dynamic object

I am going to summarize my problem into the following code snippet. List list = new List() { 5, 56, 2, 4, 63, 2 }; Console.WriteLine(list.First()); Above code is working fine. Now I tried the following dynamic dList = list; …
santosh singh
  • 27,666
  • 26
  • 83
  • 129