首页 \ 问答 \ 更新属性或创建新元素(如果不存在)Lambda c#(Update property or create new element if it does not exist Lambda c#)

更新属性或创建新元素(如果不存在)Lambda c#(Update property or create new element if it does not exist Lambda c#)

我有一个大的List <> of Name / Value对,需要能够找到此列表中是否存在特定的Name ...如果是,则更新该Value,如果不是,则创建一个新的Name / Value对并​​将其追加到我的列表。

Lambda语法是做什么的?

我试过使用.Where .DefaultIfEmpty,但它只是返回一个空对象但是没有将它附加到我原来的'myList'

myList.Where(x => x.Name == 'some name').DefaultIfEmpty(new myobj(){ Name = 'some name').First().Value = 'some value';

我必须这四个多个名称,所以如果我有一个简单的语法,将使它伟大=)


I have a large List<> of Name/Value pairs and need to be able to find if a particular Name exist in this list...if so update that Value, if NOT then create a new Name/Value pair and append it to my List.

What is the Lambda syntax to do this?

I have tried using .Where .DefaultIfEmpty but it just returns an empty object but does not append it to my original 'myList'

myList.Where(x => x.Name == 'some name').DefaultIfEmpty(new myobj(){ Name = 'some name').First().Value = 'some value';

I have to do this four multiple Names so if I had a simple syntax that would make it great =)


原文:https://stackoverflow.com/questions/17552180
更新时间:2022-04-23 17:04

最满意答案

您可能已经解决了这个问题,因为它已经很老了,但这可能对其他人有所帮助。 问题可能是由于Visual Studio 2012中的项目属性中的错误。

如果你前往:

项目属性> C / C ++>预处理器>预处理器定义

并添加标志:

_NO_ASYNCRTIMP;

这可以防止编译器尝试从DLL中查找C ++ REST SDK函数。 它应该解决你的pplx链接错误。

其他一些重要的注意事项:

  • 确保您正在为项目使用v110二进制文件 ,因为它们适用于Visual Studio 2012
  • 您可能会在互联网上遇到一些不明智的建议,将“禁用wchar_t”作为本机类型。 这通常是一个坏主意,因为wchar_t是本机类型,而C ++ REST SDK依赖于它。
  • 如果来自C ++ REST SDK的v110二进制文件未正确链接,请尝试Windows XP版本(v110_xp)

You may have resolved this issue since it's so old, but this might help others. The issue could be due to an error in the project properties in Visual Studio 2012.

If you head to:

Project Properties > C/C++ > Preprocessor > Preprocessor Definitions

And add the flag:

_NO_ASYNCRTIMP;

This prevents the compiler from trying to find the C++ REST SDK functions from a DLL. It should resolve your pplx linking errors.

Some other points that are important to note:

  • ensure that you are using the v110 binaries for your project, as those are intended for Visual Studio 2012
  • You may run across some ill-advised suggestions around the internet to "disable wchar_t" as a native type. This is generally a bad idea, because wchar_t IS a native type and the C++ REST SDK depends on it.
  • If the v110 binaries from the C++ REST SDK aren't linking properly, try the Windows XP version (v110_xp)

相关问答

更多
  • 虽然回答这个问题可能要迟到一点,但迟到总比没有好。 以下是我的看法: 如果它不向后兼容会发生什么? 你的解决方案会破坏,虽然下一个版本的程序集不是向后兼容的极不可能,你可以使用.Net / CLR的新版本运行任何旧的.net程序,最近它会显示弃用消息,并且它只会在漂亮之后很长一段时间它不会立即停止支持,就像这种情况一样。 只有向后兼容时,程序集才是下一个版本,否则它是新程序集。 为什么Microsoft.WindowsAzure.ServiceRuntime不是NuGet包? 首先要了解Nuget存在的原因 ...
  • Nuget不会将它添加到Test项目内的常规“packages.config”文件中。 它将它添加到“.nuget”文件夹中的“packages.config”文件夹中。 这是因为您正在使用NuGet 2.7或更高版本并且具有仍由旧程序包还原方法“MSBuild-integrated restore”配置的解决方案 。 这将导致构建失败,并显示一条错误,指出您尚未同意恢复软件包。 Visual Studio将跳过自动包还原。 如何更改,强制VS自动获取包? 要解决此问题,您可以按照以下步骤操作: 关闭Vis ...
  • 看起来该包需要一些手动设置。 我引用https://preview.nuget.org/packages/UwpDesktop/10.0.14393.3 “ 我们正在努力使用最新版本更新此软件包。同时作为解决方法,请将以下winmds添加到您的项目...... ” 也许您想要降级该软件包并安装以前的版本,或者按照这些步骤来使用它。 First, Thank you Tetsuya, Leo, bradbury9 for many hint. I resolve this issue by my self. ...
  • 如果你下载你的nuget包,并解压缩它(是的,它只是一个zip文件)。 您会发现您的DLL不在lib目录中。 通常,在nuget包中,任何dll都需要在lib/ 例如,如果您的DLL针对netstandard1.6然后在nuget包中,您的DLL的路径将是lib/netstandard1.6/SixtyThreeBits.Libraries.dll 在您的包中,您的DLL位于SixtyThreeBitsLibraries/SixtyThreeBits.Libraries. ...
  • 尝试使用Visual Studio 2015在一个将目标框架设置为.NET Framework 4.0的项目中构建它时,我得到了同样的错误。 将目标框架设置为.NET Framework 4.6.1为我解决了这个问题。 如果可能的话,我会建议使用较新版本的Visual Studio,或者通过命令行使用较新的框架自己编译它。 如果您希望稍后再做其他堆栈溢出应答,可能会有所帮助。 如何在没有安装Visual Studio的情况下构建.NET 4.6 Framework应用程序? I got the same e ...
  • 我的解决方案是: 退出Visual Studio。 再次启动Visual Studio。 卸载软件包。 重新安装软件包。 之后,程序包管理器输出窗口中不会显示异常。 我仍然没有绑定重定向的包,但可能根本不需要。 My solution was: Exit Visual Studio. Start Visual Studio again. Uninstall the package. Install the package again. After that, no exception was shown i ...
  • 您可能已经解决了这个问题,因为它已经很老了,但这可能对其他人有所帮助。 问题可能是由于Visual Studio 2012中的项目属性中的错误。 如果你前往: 项目属性> C / C ++>预处理器>预处理器定义 并添加标志: _NO_ASYNCRTIMP; 这可以防止编译器尝试从DLL中查找C ++ REST SDK函数。 它应该解决你的pplx链接错误。 其他一些重要的注意事项: 确保您正在为项目使用v110二进制文件 ,因为它们适用于Visual Studio 2012 您可能会在互联网上遇到一些不明 ...
  • 这里的问题是程序集引用了NewtonSoft.Json的版本6,这在运行时找不到,因为只有更高版本存在。 这通常适用于绑定重定向。 在安装软件包时,NuGet应使用packages.config自动生成必要的绑定重定向到runnable(exe,web apps)项目。 对于基于PackageReference的项目,有时(测试项目,插件库,...)也需要告诉msbuild根据已解析的程序集自动生成所需的绑定重定向。 这可以通过将其添加到csproj文件来完成:
  • 回购邮件位于https://nuget.org/api/v2/ 如果那个网址不够,Fiddler应该会有所帮助。 Well the repo is located at https://nuget.org/api/v2/ If that url isn't enough, Fiddler should be of some help.
  • NuGet将您的NuGet包视为仅包含语言资源的本地化NuGet包 。 不引用此类NuGet包中的程序集。 例如,如果将My.Resources.dll重命名为My.Resources2.dll,则NuGet将引用该程序集。 基本上任何以.resources.dll结尾的文件被NuGet认为是资源程序集在安装NuGet包时都不会被引用。 NuGet is treating your NuGet package as a localized NuGet package that only contains l ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)