variable-declaration

C#- using a variable in an 'enclosing' local scope?

余生颓废 提交于 2019-12-13 02:17:32
问题 I am trying to add some new features to a C# application- in particular, trying to replicate some of its behavior, but inside a web browser, rather than in the application, as it currently is. I am trying to call a method that has been defined in the Browser.cs class from inside a method in the MainWindow.cs class. The method is defined in Browser.cs with: public partial class Browser : Form{ public Browser(){ ... } public void Browser_Load(object sender, EventArgs e){ webKitBrowser1.Navigate

Is a variable declared in a loop body preserved during iterations?

梦想与她 提交于 2019-12-12 20:25:30
问题 Consider a loop in C which declares a character array in the loop's body. At each iteration, a character of array is modified until the end is reached. At the end, the variable is printed. The description would expand to the next code: #include <stdio.h> int main(void) { int i = 0; for (;;) {/* same as: while(1) { */ char x[5]; x[i] = '0' + i; if (++i == 4) { x[i] = '\0'; /* terminate string with null byte */ printf("%s\n", x); break; } } return 0; Many may expect 0123 as output. But for some

F#: Destructuring bind with a discriminated union

你离开我真会死。 提交于 2019-12-12 10:36:51
问题 open System let x = (1, 2) let (p, q) = x printfn "A %A" x printfn "B %A %A" p q let y = Some(1, 2) try let None = y () with | ex -> printfn "C %A" ex let Some(r, s) = y printfn "D %A" y // printfn "E %A %A" r s http://ideone.com/cS9bK0 When I uncomment the last line, the compiler rejects the code complaining /home/rRiy1O/prog.fs(16,19): error FS0039: The value or constructor 'r' is not defined /home/rRiy1O/prog.fs(16,21): error FS0039: The value or constructor 's' is not defined Is it not

Oracle SQL: Declaring variables to use in queries & subqueries

家住魔仙堡 提交于 2019-12-12 03:35:12
问题 I'm somewhat new to this Oracle database and I've inherited a large-ish query with several sub-queries. I'd like to optimize it by declaring a few variables to reference later on within the queries, but I can't seem to get it right. Here is an extremely dumbed-down version of my query that, if I can get this in the right format, I think I can get the full version working: DECLARE outage_start_time INTEGER := 1456894800; outage_end_time INTEGER := 1457586000; DST_offset INTEGER := 0; time_zone

what's wrong with declaring a variable inside if's condition?

感情迁移 提交于 2019-12-10 01:23:10
问题 Perhaps I am getting rusty (have been writing in Python recently). Why does this not compile? if ( (int i=f()) == 0) without the () around the int i=f() I get another, much more reasonable error of i is not being boolean. But that's why I wanted the parentheses in the first place! My guess would be that using the parentheses makes it into an expression, and that declaration statements are not allowed in an expression. Is it so? And if yes, is it one of the C++'s syntax quirks? BTW, I was

double as true / false

泪湿孤枕 提交于 2019-12-08 19:32:01
问题 Bjarne suggests using the condition in if's as scope restriction. In particular this example. if ( double d = fd() ) { // d in scope here... } I'm curios how to interpret the declaration in a true / false sense. It's a declaration It's a double. Edit: It's in 6.3.2.1 The C++ programming language as a recommendation. Edit2: templatetypedefs suggestion of pointers, in particular with dynamic casts, might give insight to Bjarnes suggestion. SteveJessop tells me: - A condition is not an

Should I declare a variable inside or outside the main function?

本小妞迷上赌 提交于 2019-12-08 11:22:10
问题 In C++, it is advisable to declare global variables inside the main program, or outside it, before everything else? I mean, what is the difference between #include <iostream> int variable; int main() { //my program return 0; } and #include <iostream> int main() { int variable; //my program return 0; } In which case should I use which one? 回答1: In the first case variable is accessible from all other functions in the file (i.e. it has global scope) whereas in the second case it is only

Declare a new variable for each iteration in a for loop

∥☆過路亽.° 提交于 2019-12-08 05:53:58
问题 How would I declare a new variable through each iteration of a for loop? For example: for (int i = 1; i <= 4; i++) { int var1 = i; // in the second iteration, I want a variable var2 set to i, etc. } After the loop is completed, I want 4 variables, named var1 , var2 , var3 , and var4 , each set to 1 , 2 , 3 , and 4 , respectively (when I set var1 to i in the above code, I am essentially setting it to 1 since that is the value of i throughout that specific iteration). 回答1: use array, list, map

window[name] equivalent to dynamically access const and let declarations

て烟熏妆下的殇ゞ 提交于 2019-12-08 05:13:31
问题 The old style JavaScript var declaration outside of a closure is global (top-level scope) and can be accessed in a browser from the window object. For example, the declaration var x = 3; can be accessed with window['x'] . How do you similarly access a const or let declaration given the name (string) of the declaration? var x = 3; const y = 7; let z = 21; console.log('x = ' + window['x']); //x = 3 console.log('y = ' + window['y']); //y = undefined console.log('z = ' + window['z']); //z =

Declare a new variable for each iteration in a for loop

五迷三道 提交于 2019-12-06 16:48:52
How would I declare a new variable through each iteration of a for loop? For example: for (int i = 1; i <= 4; i++) { int var1 = i; // in the second iteration, I want a variable var2 set to i, etc. } After the loop is completed, I want 4 variables, named var1 , var2 , var3 , and var4 , each set to 1 , 2 , 3 , and 4 , respectively (when I set var1 to i in the above code, I am essentially setting it to 1 since that is the value of i throughout that specific iteration). use array, list, map or other kind of data structure. e.g. int[] arr = new int[4]; for (int i = 1; i <= 4; i++) { // well, we