parameters

Pass parameters to constructor, when initializing a lazy instance

ⅰ亾dé卋堺 提交于 2020-01-10 09:34:51
问题 public class myClass { public myClass(String InstanceName) { Name = InstanceName; } public String Name { get; set; } } // Now using myClass lazily I have: Lazy<myClass> myLazy; Console.WriteLine(myLazy.Value.Name); My question is how to pass InstanceName to myClass constructor when we are using a lazy instance ? 回答1: Try this: Lazy<myClass> myLazy = new Lazy<myClass>(() => new myClass(InstanceName)); Remember that the expression is evaluated lazily, so if you change the value of the variable

Symfony2: How to pass url querystring parameters to controllers?

為{幸葍}努か 提交于 2020-01-10 08:49:53
问题 Maybe I am missing something but there doesn't seem to be a way to define querystring parameters in routes in Symfony2 so that they can be passed into a controller. For instance, instead of generating a URI like /blog/my-blog-post (from Symfony2's routing documentation) and passing it to the following route: # app/config/routing.yml blog_show: pattern: /blog/{slug} defaults: { _controller: AcmeBlogBundle:Blog:show } I would prefer to generate a URI like /blog?slug=my-blog-post . The problem

Flex: Sending parameters to Alert closeHandler

帅比萌擦擦* 提交于 2020-01-10 03:47:27
问题 Is it possible to send parameters to a closeHandler Alert function? The fisrt parameter the function gets is the CloseEvent, but how to send another one? <s:Button id="btnLoadLocalData" label="Load data" click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, loadLocalData(???parameters???), null, Alert.OK);"/> Thank you! 回答1: This should be possible using Flex's dynamic function construction. A similar question was asked here. Here's an example: The parameters

How to remove parameters in URL and display it in address bar without causing redirect in Javascript?

不想你离开。 提交于 2020-01-09 11:07:08
问题 I have found numerous answers on how to extract the URL without the parameters. How do you rewrite the URL in the address bar without causing the page to reload with the new URL? shortURL = top.location.href.substring(0, top.location.href.indexOf('?')); top.location.href = shortURL // Causes redirect The goal is to extract the parameters in Javascript but not display them in the address bar. 回答1: In modern browsers with support for the History object, you can use either history.replaceState()

Extract parameters before last parameter in “$@”

放肆的年华 提交于 2020-01-09 06:05:11
问题 I'm trying to create a Bash script that will extract the last parameter given from the command line into a variable to be used elsewhere. Here's the script I'm working on: #!/bin/bash # compact - archive and compact file/folder(s) eval LAST=\$$# FILES="$@" NAME=$LAST # Usage - display usage if no parameters are given if [[ -z $NAME ]]; then echo "compact <file> <folder>... <compressed-name>.tar.gz" exit fi # Check if an archive name has been given if [[ -f $NAME ]]; then echo "File exists or

Extract parameters before last parameter in “$@”

南楼画角 提交于 2020-01-09 06:05:09
问题 I'm trying to create a Bash script that will extract the last parameter given from the command line into a variable to be used elsewhere. Here's the script I'm working on: #!/bin/bash # compact - archive and compact file/folder(s) eval LAST=\$$# FILES="$@" NAME=$LAST # Usage - display usage if no parameters are given if [[ -z $NAME ]]; then echo "compact <file> <folder>... <compressed-name>.tar.gz" exit fi # Check if an archive name has been given if [[ -f $NAME ]]; then echo "File exists or

What does *& mean in a function parameter

喜夏-厌秋 提交于 2020-01-09 05:17:48
问题 If I have a function that takes int *& , what does it means? How can I pass just an int or a pointer int to that function? function(int *& mynumber); Whenever I try to pass a pointer to that function it says: error: no matching function for call to 'function(int *)' note: candidate is 'function(int *&)' 回答1: It's a reference to a pointer to an int. This means the function in question can modify the pointer as well as the int itself. You can just pass a pointer in, the one complication being

How to escape special characters in PowerShell?

淺唱寂寞╮ 提交于 2020-01-09 03:53:10
问题 When my PowerShell script runs, it prompts the user for a password parameter. That password can contain any number of special characters like *\~;(%?.:@/ That password is then used as a parameter for a .exe command, but it is often incorrect due to some special characters not being escaped properly. An example past password was $(?-.?-(. The only characters I needed to escape was '(', which I replaced with '`(' to make it work. However, that password is now expired. The new password is

html “data-” attribute as javascript parameter

眉间皱痕 提交于 2020-01-09 01:56:13
问题 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? 回答1: 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'));" DEMO:

Parameterized Queries with LIKE and IN conditions

心不动则不痛 提交于 2020-01-08 16:02:10
问题 Parameterized Queries in .Net always look like this in the examples: SqlCommand comm = new SqlCommand(@" SELECT * FROM Products WHERE Category_ID = @categoryid ", conn); comm.Parameters.Add("@categoryid", SqlDbType.Int); comm.Parameters["@categoryid"].Value = CategoryID; But I'm running into a brick wall trying to do the following: SqlCommand comm = new SqlCommand(@" SELECT * FROM Products WHERE Category_ID IN (@categoryids) OR name LIKE '%@name%' ", conn); comm.Parameters.Add("@categoryids",