Tag: C#的

在C#中创build单个项目列表的快捷方式

在C#中,是否有一个内联快捷方式来实例化List <T>只有一个项目。 我现在在做: new List<string>( new string[] { "title" } )) 在任何地方使用此代码都会降低可读性 我想过使用这样的实用工具: public static List<T> SingleItemList<T>( T value ) { return (new List<T>( new T[] { value } )); } 所以我可以这样做: SingleItemList("title"); 有没有更简洁的方法? 谢谢。

如何调用另一个控制器操作从Mvc中的控制器

我需要从控制器A调用控制器B操作FileUploadMsgView,并且需要传递一个参数。 Code—its not going to the controller B's FileUploadMsgView(). In ControllerA private void Test() { try {//some codes here ViewBag.FileUploadMsg = "File uploaded successfully."; ViewBag.FileUploadFlag = "2"; RedirectToAction("B", "FileUploadMsgView", new { FileUploadMsg = "File uploaded successfully" }); } In ControllerB receiving part public ActionResult FileUploadMsgView(string FileUploadMsg) { return View(); }

string.Format()给出“inputstring格式不正确”

我在这里做错了什么? string tmp = @" if (UseImageFiles) { vCalHeader += ""<td><img onmousedown='' src= '{0}cal_fastreverse.gif' width='13px' height='9' onmouseover='changeBorder(this, 0)' onmouseout='changeBorder(this, 1)' style='border:1px solid white'></td>\n""; //Year scroller (decrease 1 year) calHeight += 22; }"; string x = "xter"; tmp = string.Format(tmp, x); 我明白了 inputstring的格式不正确 当试图改变{0} 。 我在C#和WinForms中这样做。 格式exception未处理 inputstring的格式不正确 排查提示问题: 确保你的方法参数是正确的格式。 将string转换为datetime时,parsingstring以将每个variables放入DateTime对象之前取出date。

http错误503服务不可用。 应用程序池停止访问网站

有这个post的数量,我现在已经尝试了很多东西。 但无济于事。 我自己是一个Winforms开发人员,几天前我开始在这个Web上工作,因为我的公司正在采取Webscheme。 我有一个ASP.Net项目,我想在本地IIS上承载它。 在“ Project properties -> Web设置”中,我select了“ Use Local IIS Server ,并将url作为localhost/MyApp 。 我试着在我的firefox浏览器上访问它,并收到HTTP Error 503. The service is unavailable. 以前,我得到了很多其他的错误,我一个接一个地修复了这些错误。 但是碰到这个。 这些是我在我的项目中的设置 应用程序池设置为ASP.Net v4.0经典 应用程序池Enable 32 bit Application属性为true 应用程序池已启动 项目生成属性设置为Any CPU的目标框架 但我想提一个奇怪的行为。 以下是我正在面对的事情 应用程序池已启动 我尝试访问我的本地网站(通过提供url作为localhost/MyApp ) 我收到错误作为HTTP Error 503. The service is unavailable 应用程序池已停止 我已经看到下面的链接 ,我已经试过了。 对于上述行为,我到达了这里 。 根据这个链接,计算机名不应该有. 在里面。 我没有任何 在我的电脑名称,但确实有-在它。 […]

如何在NSString中find最后一个子string?

我怎样才能得到另一个NSString中的最后一个NSString? 例如,在“abc def ghi abc def ghi”中,我想查找第二个“abc”的索引,而不是第一个索引。 我知道我可以用一堆rangeOfStrings做到这一点,但是那里已经有一个函数了吗?

将值附加到查询string

我有一组类似于下面的列表中的URL http://somesite.com/backup/lol.php?id=1&server=4&location=us http://somesite.com/news.php?article=1&lang=en 我设法使用下面的代码获取查询string: myurl = longurl.Split('?'); NameValueCollection qs = HttpUtility.ParseQueryString(myurl [1]); foreach (string lol in qs) { // results will return } 但是它只会根据提供的URL返回id , server , location等参数。 我需要的是添加/附加值到现有的查询string。 例如与URL: http://somesite.com/backup/index.php?action=login&attempts=1 我需要改变查询string参数的值: 行动= login1 尝试= 11 正如你所看到的,我为每个值附加了“1”。 我需要从一个string中获取一组不同的查询string的URL,并在每个参数的末尾添加一个值,再次将它们添加到列表中。

为什么甚至有可能改变一个私人成员,或在C#中使用reflection运行私有方法?

我最近遇到了一个我正在使用C#的问题,通过使用reflection设置私有成员来解决这个问题。 我惊讶地发现,设置一个私人成员/字段,并运行私有方法是C#允许和可能的东西。 这不是如何做这些事情的问题,他们是有据可查的,我的问题是:为什么? 如果将字段/成员/方法设置为私有/内部,为什么C#作为一种语言允许将这些字段设置在范围之外? 我认为这会抛出某种例外。 如果这个类想让他们改变或设置不会有一个方法或构造?

结构构造函数:“控制返回给调用者之前,必须完全分配字段”。

这里是我想写的一个结构: public struct AttackTraits { public AttackTraits(double probability, int damage, float distance) { Probability = probability; Distance = distance; Damage = damage; } private double probability; public double Probability { get { return probability; } set { if (value > 1 || value < 0) { throw new ArgumentOutOfRangeException("Probability values must be in the range […]

这个程序如何工作?

#include <stdio.h> int main() { float a = 1234.5f; printf("%d\n", a); return 0; } 它显示一个0 ! 这怎么可能? 什么是推理? 我有意在printf语句中join%d来研究printf的行为。

如何加载与所有引用recursion的程序集到AppDomain?

我想加载到一个新的AppDomain一些程序集,其中有一个复杂的引用树(MyDll.dll – > Microsoft.Office.Interop.Excel.dll – > Microsoft.Vbe.Interop.dll – > Office.dll – > stdole.dll ) 据我所知,当一个程序集加载到AppDomain ,它的引用不会自动加载,我必须手动加载它们。 所以当我这样做时: string dir = @"SomePath"; // different from AppDomain.CurrentDomain.BaseDirectory string path = System.IO.Path.Combine(dir, "MyDll.dll"); AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; setup.ApplicationBase = dir; AppDomain domain = AppDomain.CreateDomain("SomeAppDomain", null, setup); domain.Load(AssemblyName.GetAssemblyName(path)); 并得到FileNotFoundException : 无法加载文件或程序集'MyDll,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'或其依赖项之一。 该系统找不到指定的文件。 我认为关键是它的一个依赖 […]