我通过代码后面调用一个IValueConverter类,但我不知道该在Type targetType参数中添加什么.该对象string只是使用它给我'无效的表达术语'字符串'
我调用转换器的代码
secondConverter.Convert(score, string, null, CultureInfo.CurrentCulture);
Run Code Online (Sandbox Code Playgroud)
转换器类
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
TimeSpan ts = new TimeSpan(0, 0, (int)value);
return String.Format("{0:D2}:{1:D2}:{2:D2}",
ts.Hours,
ts.Minutes,
ts.Seconds);
}
Run Code Online (Sandbox Code Playgroud) 我有一个 HTML 页面字符串,我想从 HTML 页面的开头删除一些字符串。我想删除的代码可以是
<!DOCTYPE HTML>
或者
<!DOCTYPE anything in between>
无论如何,它总是以 开始<!DOCTYPE并结束>。如何搜索该行并将其从 HTML 页面中删除?
到目前为止,我设法<!DOCTYPE HTML>使用以下代码搜索并删除第一个字符串
PageString = e.Result.Replace("<!DOCTYPE HTML>", "").Trim();
Run Code Online (Sandbox Code Playgroud)
但第二个呢?
假设我有以下 HTML 字符串
<head>
</head>
<body>
<img src="stickman.gif" width="24" height="39" alt="Stickman">
<a href="http://www.w3schools.com">W3Schools</a>
</body>
Run Code Online (Sandbox Code Playgroud)
我想在<head>标签之间添加一个字符串。所以最终的 HTML 字符串变成
<head>
<base href="http://www.w3schools.com/images/">
</head>
<body>
<img src="stickman.gif" width="24" height="39" alt="Stickman">
<a href="http://www.w3schools.com">W3Schools</a>
</body>
Run Code Online (Sandbox Code Playgroud)
所以我必须搜索第一次出现的<head>字符串,然后在后面插入<base href="http://www.w3schools.com/images/">。
我如何在 C# 中做到这一点。
我还在学习,LINQ所以忍受我:).我的问题,如何将以下代码转换为LINQ
int count = 0;
foreach (var item in settings.FavouritesSetting)
{
if (item.FavouriteType != Constants.FavouriteType.Folder)
count++;
}
return count.ToString();
Run Code Online (Sandbox Code Playgroud) 我有以下代码来返回 Dictionary<int, string> buttonGroups
值匹配某些字符串的项目.
public static void RemoveColorRange(List<Button> buttons, int[] matches)
{
Dictionary<int, string> buttonGroups = new Dictionary<int, string>();
foreach (Button btn in buttons)
{
if ((int)btn.Tag == matches[0] || (int)btn.Tag == matches[1])
continue;
SolidColorBrush brush = (SolidColorBrush)btn.Background;
Color color = new Color();
color = brush.Color;
buttonGroups.Add((int)btn.Tag, closestColor(color));
}
var buttonMatches = buttonGroups.Where(x => x.Value == 'somestring');
}
Run Code Online (Sandbox Code Playgroud)
但是它返回以下类型而不是字典对象.我似乎无法从buttonMatches中检索任何值.我错过了什么?
{System.Linq.Enumerable.WhereEnumerableIterator<System.Collections.Generic.KeyValuePair<int,string>>}
Run Code Online (Sandbox Code Playgroud) 我有一个Layer包含一个Content对象作为属性的集合。如何Content将其转换为原始对象以在 LINQ 语句中获取其属性?
例如:
var item = Layers.FirstOfDefault(x =>(PushPin)x.Content.Description == "xyz");
Run Code Online (Sandbox Code Playgroud)
在这种情况下Content是PushPin对象类型,我想将其Description属性与xyz
我有一个按钮列表,List<Button> buttons每个按钮都包含一个标签对象.
然后是一个字典对象
Dictionary<int, string> buttonGroups = new Dictionary<int, string>();
Run Code Online (Sandbox Code Playgroud)
如何使用LINQ 从其标签与键匹配的位置返回List按钮?List<Button> buttonsbuttonGroups
我正在使用Visual Studio 2013开发Windows Universal App.
我刚刚在我的解决方案中通过nuget和App.cs升级了MVVMCross,以下方法用于工作而没有问题
public class App : MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();
RegisterAppStart<ViewModels.StartViewModel>();
}
}
Run Code Online (Sandbox Code Playgroud)
但升级后,我收到以下错误
Error 2 'System.Collections.Generic.IEnumerable<System.Type>' does not contain a definition for 'EndingWith' and no extension method 'EndingWith' accepting a first argument of type 'System.Collections.Generic.IEnumerable<System.Type>' could be found (are you missing a using directive or an assembly reference?) D:\Users\Vicky\OneDrive\Dev\WUA\KpopQuiz.Core\KpopQuiz.Core\App.cs 11 18 KpopQuiz.Core
Run Code Online (Sandbox Code Playgroud)
是EndingWith折旧还是有新的初始化方法Service?
我正在尝试捕获屏幕截图并将其保存为jpeg MediaLibrary但已收到
在lib.SavePicture(filePath,ms)中的Microsoft.Xna.Framework.ni.dll中发生System.UnauthorizedAccessException类型的第一次机会异常;
我的代码:
public static void SaveToMediaLibrary(FrameworkElement element, string title)
{
using (MemoryStream ms = new MemoryStream())
{
bmp.SaveJpeg(ms, (int)element.ActualWidth, (int)element.ActualHeight, 0, 100);
var lib = new MediaLibrary();
var filePath = string.Format(title + ".jpg");
ms.Seek(0, SeekOrigin.Begin);
lib.SavePicture(filePath, ms);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Windows Phone 8模拟器进行测试.我错过了什么?
我想将对象复制到另一个对象但删除某些属性.例如
public class A
{
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
public double CurrentWidth { get; private set; }
public double CurrentHeight { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
将对象A复制到对象B,但删除CurrentWidth和CurrentHeight属性
public class B
{
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何用最少的代码有效地完成这项工作?
如何缩短以下代码,可能使用匿名方法或扩展名LINQ.
因为我必须多次重复这段代码,所以我希望尽可能简洁.
var imagesToUnlock = App.ImageListVM.Items.Where(img => img.Category == key);
foreach (var image in imagesToUnlock)
{
image.IsLocked = false;
}
Run Code Online (Sandbox Code Playgroud)