在类构造函数C#中传递可变数量的参数(Passing variable number of parameters in class constructor C#)
我有一个类
EvoObject.cs
,其构造函数定义为:public class EvoObject { private Object _id; private List<List<Int32>> _attributes; public EvoObject(Object _id, params List<Int32> _args) { List<Int32> _attrib = new List<int>(); Debug.Assert(_args.Count >= 2, "Invalid attributes!"); this._id = _id; _attributes = new List<List<Int32>>(_args.Count); for (int _i = 0; _i < _args.Count; _i++) { _attrib.Add(_args[_i]); } _attributes.Add(_attrib); } }
其中我使用
params
接受可变数量的参数。现在我在另一个类中有另一个方法,它返回新的
EvoObject
:return new EvoObject(_author, _coAuthors, _papers, _venues);
我希望与之相关
_author
withObject _id
_coAuthors
,_papers
,_venues
withparams List<Int32> _args
在类
EvoObject.cs
构造函数中,而_coAuthors
,_papers
和_venues
:都是List<Int32>
类型的List<Int32>
我遇到错误:
return new EvoObject(_author, _coAuthors, _papers, _venues);
即
EvoObject does not contains a constructor that takes 4 arguments
。
params
如何在这里有用?I have a class
EvoObject.cs
which has a constructor defined as:public class EvoObject { private Object _id; private List<List<Int32>> _attributes; public EvoObject(Object _id, params List<Int32> _args) { List<Int32> _attrib = new List<int>(); Debug.Assert(_args.Count >= 2, "Invalid attributes!"); this._id = _id; _attributes = new List<List<Int32>>(_args.Count); for (int _i = 0; _i < _args.Count; _i++) { _attrib.Add(_args[_i]); } _attributes.Add(_attrib); } }
in which I have used
params
for accepting variable number of parameters.Now I have another method in another class which returns new
EvoObject
as:return new EvoObject(_author, _coAuthors, _papers, _venues);
in which I want to relate
_author
withObject _id
_coAuthors
,_papers
,_venues
withparams List<Int32> _args
in constructor of class
EvoObject.cs
whereas_coAuthors
,_papers
and_venues
: all are lists of typeList<Int32>
I'm getting error at line:
return new EvoObject(_author, _coAuthors, _papers, _venues);
i.e.
EvoObject does not contains a constructor that takes 4 arguments
.How
params
can be useful here?
原文:https://stackoverflow.com/questions/37415199
最满意答案
您需要打开NSExtensionActivationSupportsWebURLWithMaxCount以在Safari中提供扩展。
从模板创建非UI操作扩展目标时,会自动创建Action.js文件。 编辑文件以使用发送回所选文本
document.getSelection().toString()
You need to turn on NSExtensionActivationSupportsWebURLWithMaxCount to make extension available in Safari.
When you create a non-UI action extension target from the template, an Action.js file is automatically created. Edit the file to send back the selected text using
document.getSelection().toString()
相关问答
更多-
看起来像一个谓词可以解决它: https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html 当选择多个相同类型时,操作扩展激活规则谓词不会隐藏操作 我如何设置NSExtensionActivationRule谓词? Looks like a predicate could fix it: https://developer.apple.c ...
-
如何在IOS中的Action Extension中制作启动画面(How do i make a splash screen in Action Extension in IOS)[2022-09-19]
基本上你需要创建自己的视图控制器并在那里制作动画,直到你真正完成你的应用程序准备。 你可能想看看已经实现的东西,像这样: https : //github.com/sachinkesiraju/SKSplashView basically you need to create your own view controller and make the animations there until you actually finish your app preparations. You might wan ... -
加载时间较慢的原因是我在调试模式下启动了应用程序扩展。 在没有调试器的情况下运行应用程序的速度显着加快。 根本没有考虑到这一点,但现在它像一个魅力:) The reason for the slow loading times was that I launched the app extension in debug mode. Running the app without the debugger it was significantly faster. Did not consider this a ...
-
适用于Safari中所选文本的iOS 8 Action Extension(iOS 8 Action Extension for selected text in Safari)[2019-11-28]
您需要打开NSExtensionActivationSupportsWebURLWithMaxCount以在Safari中提供扩展。 从模板创建非UI操作扩展目标时,会自动创建Action.js文件。 编辑文件以使用发送回所选文本 document.getSelection().toString() You need to turn on NSExtensionActivationSupportsWebURLWithMaxCount to make extension available in Safar ... -
看来我的问题与扩展程序的高内存使用率有关。 出于某种原因,系统似乎只有在没有连接到Xcode时才会杀死具有高内存使用率的扩展。 扩展不仅在附加时工作正常,而且没有迹象表明您的内存使用率很高(似乎没有警告)。 改变扩展以减少资源浪费解决了我的问题,因为崩溃只发生在扩展处理大量数据时。 It seems my problem was related to high memory usage by the extension. For some reason, the system seems to kill e ...
-
无法使用iframe iPad iOS 8 Safari中的输入类型文本(Can't use input type text from iframe iPad iOS 8 Safari)[2023-11-26]
我还没有解决问题,但我找到了原因,所以对我来说不再是问题。 页面和iframe中加载的页面的组合对于iPads Safari来说太大了。 如果您转到iframe内的文本字段并调用屏幕键盘,则会超出Safari的最大内存,因此应用程序会重新加载页面。 I have not solved the problem, but I have found the reason and so for me it is no longer a problem. The combination of the page and ... -
回答我自己的问题:至少有一种方法可以实现 - 使用NotificationCenter,在本答案中描述的“为什么viewWillAppear不会被调用...”问题。 如果有人有更好的主意 - 我会很乐意尝试它。 Answering my own question: there is at least one way to do it - using NotificationCenter, described in this answer to the "Why does viewWillAppear not ...
-
是否可以更改iOS 8 Action Extension的视图大小?(Is it possible to change the view size of iOS 8 Action Extension?)[2022-10-08]
经过一番四处搜寻,我发现我需要做的所有事情都放在了地上 [self setPreferredContentSize:CGSizeMake(760.0f, 1024)]; 在viewDidLoad中 After a bit of searching around I found all I needed to do was put [self setPreferredContentSize:CGSizeMake(760.0f, 1024)]; in viewDidLoad -
请查看此答案,了解如何将文本选择返回到您的后台页面, https://stackoverflow.com/a/2645306/897414 Take a look at this answer for an example of how to get text selection back to your background page, https://stackoverflow.com/a/2645306/897414
-
目前,没有。 我确实提交了一个功能请求,在Mail中有许多动作扩展的机会! 我建议你这样做可能会在这背后优先考虑。 Currently, no. I did file a feature request for this, many opportunities for action extensions in Mail! I would suggest that you do the same to possibly get some priority behind this.