我问了一个问题,其中一个响应包含以下LINQ代码:
var selected = lstAvailableColors.Cast<ListItem>().Where(i => i.Selected).ToList();
selected.ForEach( x => { lstSelectedColors.Items.Add(x); });
selected.ForEach( x => { lstAvailableColors.Items.Remove(x);});
Run Code Online (Sandbox Code Playgroud)
有人可以解释上面的LINQ总新手吗?
我在互联网上看到了很多关于元标记的不同观点.我已经使用它们一段时间了,但我现在想知道我是否一直在使用当前的最佳实践.
我知道描述是最重要的...
<meta name="description" content="This is not a website" />
Run Code Online (Sandbox Code Playgroud)
但是其他元标记怎么样?我应该使用除描述标签以外的其他东西吗?例如,有人说使用关键字现在是不好的做法,因为有些网站过度使用它们,它可能导致在搜索引擎的垃圾邮件文件夹中引导网站.
最后,编写描述元标记时的最佳做法是什么?使用我的个人示例,我现在有一个网站引用各种歌曲.我应该这样做:
<meta name="description" content="MyWebsite - Here, there are songs" />
Run Code Online (Sandbox Code Playgroud)
在每个不同的页面上或类似的东西:
<meta name="description" content="Song Title X, Artist Y" />
Run Code Online (Sandbox Code Playgroud)
要么 :
<meta name="description" content="MyWebsite - Here, there are songs | Song Title X, Artist Y" />
Run Code Online (Sandbox Code Playgroud)
或者前一个的任何组合......或其他什么?
谢谢 !
重新阅读这个问题:
C++中"new"和"malloc"和"calloc"有什么区别?
我检查了答案,但没有人回答这个问题:
有几个原因(我可以想到两个).
让最好的浮动到顶部.
我正在为一个不支持Unicode字符串但仍支持多字节ANSI字符串的库的PInvoke包装器工作.在调查关于库的FxCop报告时,我注意到使用的字符串编组有一些有趣的副作用.PInvoke方法使用"最佳拟合"映射来创建单字节ANSI字符串.为了说明,这是一个方法的样子:
[DllImport("thedll.dll", CharSet=CharSet.Ansi)]
public static extern int CreateNewResource(string resourceName);
Run Code Online (Sandbox Code Playgroud)
使用包含非ASCII字符的字符串调用此函数的结果是Windows找到"关闭"字符,通常这看起来最终是"???".如果我们假装'a'是非ASCII字符,那么将"cat"作为参数传递将创建名为"c?t"的资源.
如果我遵循FxCop规则中的指导原则,我最终会得到这样的结果:
[DllImport("thedll.dll", CharSet=CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern int CreateNewResource([MarshalAs(UnmanagedType.LPStr)] string resourceName);
Run Code Online (Sandbox Code Playgroud)
这引入了行为的变化; 现在当一个字符无法映射时抛出一个异常.这让我很担心,因为这是一个突破性的变化,所以我想尝试将字符串编组为多字节ANSI,但我看不到这样做的方法. UnmanagedType.LPStr被指定为单字节ANSI字符串,LPTStr will be Unicode or ANSI depending on the system, and LPWStr is not what the library expects.
How would I tell PInvoke to marshal the string as a multibyte string? I see there's a WideCharToMultiByte()
UnmanagedType.LPStrLPTStr will be Unicode or ANSI depending on the system, and LPWStr is …
我有这样的代码了我的服务器在这里(是的,我知道ASMX是一个坏主意,但WCF不会因为某些原因在所有的工作):
<%@ WebService Language="C#" Class="Test" %>
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://smplsite.com/smplAccess")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Test : System.Web.Services.WebService
{
State s;
public Test()
{
s = (Session["foo"] ?? (Session["foo"] = new State())) as State ;
}
[WebMethod(EnableSession = true)]
public void Set(int j) { i=j; }
[WebMethod(EnableSession = true)]
public int Get() { return i; }
}
class State
{
public int i = 5;
}
Run Code Online (Sandbox Code Playgroud)
当我运行以下代码时:
class Program
{
static void Main(string[] args)
{ …Run Code Online (Sandbox Code Playgroud) 我有三个模型,简化为例子:
class Customer(models.Model):
email = models.CharField(max_length=128)
class Order(models.Model):
customer = models.ForeignKey(Customer)
order_status = models.CharField(blank=True, max_length=256)
class Lineitem(models.Model):
order = models.ForeignKey(Order)
quantity = models.IntegerField(blank=True)
price = models.DecimalField(max_digits=6, decimal_places=2)
Run Code Online (Sandbox Code Playgroud)
我想查询客户(可能使用过滤器)并注释他们花费的总额(即总和(价格*数量))
我试过了:
Customer.objects.filter(something).annotate(total_spent=Sum(F('order__lineitem__quantity') * F('order__lineitem__price')))
似乎Sum()不能与F()表达式一起使用.还有另一种方法吗?
我正在寻找一个像集合一样的数据结构,因为它不允许插入重复项,但也知道项目的插入顺序.它基本上是一个集合和列表/向量的组合.
我只是使用列表/向量并自己检查重复项,但我们需要快速重复验证,因为结构的大小可能会变得非常大.
我部署了一个现有程序,其中一些客户数据库的字段设置为非空,而其他客户数据库可以为空.我需要运行一个补丁来更正数据库,以便该列可以为空,但不需要针对所有数据库运行它,只需要它不正确的数据库.是否有一个可以在SQL Server中使用的简单方法来执行此检查?最好是可以作为SQL脚本的一部分运行的东西.
我正在尝试在我的开发数据库上执行一些离线维护(从实时备份中删除数据库),但是通过SQL Server Management Studio执行的"Take Offline"命令执行速度非常慢 - 大约30分钟加上现在.我只是在我的智慧结束,我似乎无法在网上找到任何可能导致速度问题,或如何解决它的参考.
有些网站建议与数据库的开放连接导致这种速度减慢,但使用此数据库的唯一应用程序是我的开发机器的IIS实例,并且服务已停止 - 没有更多的打开连接.
什么可能导致这种放缓,我该怎么做才能加快速度?
我们有一个处理艺术家和场地的网站,我们正在ASP.net MVC中开发它.
我们将艺术家视图放在文件夹(Views/Artists/..),ArtistsController,ArtistsRepository中,并遵守REST动作名称,如Show,New,Delete等.
当我们第一次模拟网站时,一切都在我们的测试环境中运行良好,因为我们的测试网址是/ artists/Show/1209但我们需要更改此网站,以便网站显示为/ artists/Madonna和/ artists/Foo-Fighters等
但是,我们如何区分有效的艺术家名称和该控制器的动作名称?!例如,艺术家/ PostComment或艺术家/ DeleteComment?我需要允许路由来处理这个问题.我们的默认Show路线是:
routes.MapRoute(
"ArtistDefault",
"artists/{artistName}",
new { controller = "Artists", action = "Show", artistName = ""}
Run Code Online (Sandbox Code Playgroud)
解决这个问题的一种方法是让我们的网站明显地运行/艺术家,但我们的控制器重命名为singular - ArtistController - 而不是ArtistsController.这会违背我们开始时的命名约定(但是嘿!).
你有其他建议吗?如果可能的话,我们也可以根据动词进行路由(因此PostComment将是一个POST,所以我们可以路由到该动作),但我不确定这是否可取,更不用说可能了.
谢谢
c++ ×2
.net ×1
asmx ×1
asp.net ×1
asp.net-mvc ×1
c# ×1
database ×1
django ×1
html ×1
linq ×1
malloc ×1
metadata ×1
new-operator ×1
performance ×1
pinvoke ×1
seo ×1
sql ×1
sql-server ×1
string ×1
t-sql ×1
web-services ×1