【发布时间】:2016-01-15 09:48:00
【问题描述】:
我编写了以下函数来创建axWindowsMediaPlayer 播放列表:
WMPLib.IWMPPlaylist p2 = axWindowsMediaPlayer.playlistCollection.newPlaylist("Playlist 1");
private void CreatePlaylist(string _currentId)
{
string selectedElementPageTypeValue = MainContentAreaBl.GetSelectedElementPageTypeValue(_currentId);
var selectedElementJumpToValue = MainContentAreaBl.GetSelectedElementValue(_currentId, "jumpTo");
if (selectedElementJumpToValue != null)
{
_currentId = selectedElementJumpToValue;
if (_currentId != null && _currentId != "menu" && selectedElementPageTypeValue == "video")
{
var playerFile = Path.Combine(Common.ContentFolderPath, MainContentAreaBl.GetSelectedElementDataPathValue(_currentId));
p2.appendItem(axWindowsMediaPlayer.newMedia(playerFile));
axWindowsMediaPlayer.currentPlaylist = p2;
CreatePlaylist(_currentId);
}
axWindowsMediaPlayer.Ctlcontrols.play();
}
}
这里var p2 在类级别声明。当我编译我的应用程序时,我收到以下错误消息:
上下文关键字“var”只能出现在局部变量声明中
但是,我不能将 var p2 = axWindowsMediaPlayer.playlistCollection.newPlaylist("Playlist 1"); 放在递归函数中,因为它会在每次迭代时创建新的播放列表。
如何在我的函数中访问 p2?
编辑 1:我在输出窗口中看到了这个
COM 引用“WMPLib”是 ActiveX 控件“AxWMPLib”的互操作程序集,但编译器使用 /link 标志将其标记为链接。此 COM 引用将被视为引用,不会被链接。
另外,现在它在axWindowsMediaplayer 上显示以下错误:
字段初始化器不能引用非静态字段、方法或属性
此信息是否与我看到的错误有关?如何解决这个问题?
【问题讨论】:
标签: c# winforms compiler-errors var