parameters

The builder pattern and a large number of mandatory parameters

吃可爱长大的小学妹 提交于 2019-12-17 08:55:14
问题 To date I use the following implementation of the builder pattern (as opposed to the implementation described here): public class Widget { public static class Builder { public Builder(String name, double price) { ... } public Widget build() { ... } public Builder manufacturer(String value) { ... } public Builder serialNumber(String value) { ... } public Builder model(String value) { ... } } private Widget(Builder builder) { ... } } This works well for most situations I've encountered where I

In a C function declaration, what does “…” as the last parameter do?

一曲冷凌霜 提交于 2019-12-17 08:48:05
问题 Often I see a function declared like this: void Feeder(char *buff, ...) what does "..." mean? 回答1: it allows a variable number of arguments of unspecified type (like printf does). you have to access them with va_start , va_arg and va_end see http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html for more information 回答2: Variadic functions Variadic functions are functions which may take a variable number of arguments and are declared with an ellipsis in place of the last parameter. An

How do the In and Out attributes work in .NET?

我们两清 提交于 2019-12-17 07:37:16
问题 I have been trying to serialize an array across an AppDomain boundary, using the following code: public int Read(byte[] buffer, int offset, int count) { return base.Read(buffer, offset, count); } As a guess, after noticing the attributes elsewhere, I marked the method's parameters with [In] and [Out] attributes, which seemed to cause the parameters to behave as if they were passed by reference. For example: public int Read([In, Out] byte[] buffer, int offset, int count) { return base.Read

Passing just a type as a parameter in C#

﹥>﹥吖頭↗ 提交于 2019-12-17 07:07:12
问题 Hypothetically it'd be handy for me to do this: foo.GetColumnValues(dm.mainColumn, int) foo.GetColumnValues(dm.mainColumn, string) where the GetColumns method will call a different method inside depending on the type passed. Yes, I could do it as a boolean flag or similar, I just wondered if there was a way to perhaps pass this, and then ask: typeof(arg[1]) or similar... I could also override the method, use generics, etc - I know there are different ways to do this, I was just curious if

Default parameter for value must be a compile time constant?

梦想与她 提交于 2019-12-17 06:53:28
问题 This is my method signature. While trying to pass end as an optional parameter it gives me this error. What should I do to resolve this? Why isn't DateTime.MinValue a constant? public static void DatesToPeriodConverter(DateTime start, DateTime end = DateTime.MinValue, out string date, out string time) 回答1: DateTime.MinValue is not a const , because the language doesn't like const on DateTime . One option is to use DateTime? instead, i.e. public static void DatesToPeriodConverter(DateTime

Default parameter for value must be a compile time constant?

混江龙づ霸主 提交于 2019-12-17 06:52:07
问题 This is my method signature. While trying to pass end as an optional parameter it gives me this error. What should I do to resolve this? Why isn't DateTime.MinValue a constant? public static void DatesToPeriodConverter(DateTime start, DateTime end = DateTime.MinValue, out string date, out string time) 回答1: DateTime.MinValue is not a const , because the language doesn't like const on DateTime . One option is to use DateTime? instead, i.e. public static void DatesToPeriodConverter(DateTime

Embed a 3rd-party JApplet in a Swing GUI & pass it parameters

笑着哭i 提交于 2019-12-17 06:51:27
问题 There's a third-party applet that I'd like to embed in my Swing application. Basically, I'd like it to be just another panel. This applet makes use of many parameters, e.g. final String config_filename = getParameter(XXX); I've seen lots of documentation about how to send parameters values via HTML, but how do you do it via code (or perhaps property files)? Any help would be appreciated! 回答1: Implement an AppletStub & set it as the stub of the applet instance. E.G. /* <applet code=

c# Using Parameters.AddWithValue in SqlDataAdapter

不羁的心 提交于 2019-12-17 05:05:18
问题 How can I use Parameters.AddWithValue with an SqlDataAdapter. Below searching codes. var da = new SqlDataAdapter("SELECT * FROM annotations WHERE annotation LIKE '%"+txtSearch.Text+"%'", _mssqlCon.connection); var dt = new DataTable(); da.Fill(dt); I rewrote the code like this: SqlDataAdapter da; da = new SqlDataAdapter("SELECT * FROM annotations WHERE annotation LIKE '%@search%'", _mssqlCon.connection); da.SelectCommand.Parameters.AddWithValue("@search",txtSearch.Text); var dt = new

Passing parameters on button action:@selector

久未见 提交于 2019-12-17 05:01:54
问题 I want to pass the movie url from my dynamically generated button to MediaPlayer: [button addTarget:self action:@selector(buttonPressed:) withObject:[speakers_mp4 objectAtIndex:[indexPath row]] forControlEvents:UIControlEventTouchUpInside]; but action:@selector() withObject: does not work? Is there any other solution? Thanks for help! 回答1: Edit. Found a neater way! One argument that the button can receive is (id)sender . This means you can create a new button, inheriting from UIButton, that

In Swift how to call method with parameters on GCD main thread?

血红的双手。 提交于 2019-12-17 04:43:10
问题 In my app I have a function that makes an NSRURLSession and sends out an NSURLRequest using sesh.dataTaskWithRequest(req, completionHandler: {(data, response, error) In the completion block for this task, I need to do some computation that adds a UIImage to the calling viewcontroller. I have a func called func displayQRCode(receiveAddr, withAmountInBTC:amountBTC) that does the UIImage-adding computation. If I try to run the view-adding code inside of the completion block, Xcode throws an