What’s the difference between “var” and “out” parameters?

What’s the difference between parameters declared with var and those declared with out? How does the compiler treat them differently (e.g., by generating different code, or by changing which diagnostics it issues)? Or do the different modifiers merely allow the programmer to document intended use of the parameters? What effect do the types of the … Read more

html “data-” attribute as javascript parameter

Lets say I have this: <div data-uid=”aaa” data-name=”bbb”, data-value=”ccc” onclick=”fun(this.data.uid, this.data-name, this.data-value)”> And this: function fun(one, two, three) { //some code } Well this is not working but I have absolutely no idea why. could someone post a working example please? Answer The easiest way to get data-* attributes is with element.getAttribute(): onclick=”fun(this.getAttribute(‘data-uid’), this.getAttribute(‘data-name’), this.getAttribute(‘data-value’));” … Read more

Hitting the 2100 parameter limit (SQL Server) when using Contains()

from f in CUSTOMERS where depts.Contains(f.DEPT_ID) select f.NAME depts is a list (IEnumerable<int>) of department ids This query works fine until you pass a large list (say around 3000 dept ids) .. then I get this error: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were … Read more

How do I call New-Object for a constructor which takes a single array parameter?

In PowerShell, I want to use New-Object to call a single-argument .Net constructor new X509Certificate2(byte[] byteArray). The problem is when I do this with a byte array from powershell, I get New-Object : Cannot find an overload for “X509Certificate2” and the argument count: “516”. Answer This approach to using new-object should work: $cert = new-object … Read more

Where are C/C++ main function’s parameters?

In C/C++, the main function receives parameters which are of type char*. int main(int argc, char* argv[]){ return 0; } argv is an array of char*, and points to strings. Where are these string located? Are they on the heap, stack, or somewhere else? Answer They are compiler magic, and implementation-dependent. AttributionSource : Link , … Read more

Which parameter set has been used?

I’ve used advanced parameter handling to support multiple parameter sets. Is there any pre-defined variable or way to determine which parameter set has been used to call the script? e.g. something like if($parameterSet -eq “set1”) { … } elseif ($parameterSet -eq “set2”) { … } ? Answer Check the $PSCmdlet variable: $PSCmdlet.ParameterSetName AttributionSource : Link … Read more

is link / href with just parameters (starting with question mark) valid?

Is this link valid? <a href=”?lang=en”>eng</a> I know the browsers treat it as expected and I know the empty link would be ok too – but is it ok to specify just the parameters? I am curious because question mark (“?”) is only a convention by most HTTP servers (AFAIK), though I admit it is … Read more

How do I pass an array as a parameter to another script?

For some reason, it looks like I cannot pass array of strings as parameter to scriptblock. What am I doing here wrong? My script which is called from another script: param( [parameter(Mandatory=$true)] [string[]]$myarr ) foreach ($elem in $myarr){ $elem } I call it from another script as $myarr = @(“111”, “222”) start-job -filepath myscript.ps1 -arg … Read more

Writing stringstream contents into ofstream

I’m currently using std::ofstream as follows: std::ofstream outFile; outFile.open(output_file); Then I attempt to pass a std::stringstream object to outFile as follows: GetHolesResults(…, std::ofstream &outFile){ float x = 1234; std::stringstream ss; ss << x << std::endl; outFile << ss; } Now my outFile contains nothing but garbage: “0012E708” repeated all over. In GetHolesResults I can write … Read more