.net-4.0

Break inner foreach loop and continue outer foreach loop

笑着哭i 提交于 2019-12-10 00:40:03
问题 If I have a nested foreach loop how do I do break the inner loop and tell the outer to continue at that point without doing any other code below the inner loop? foreach(var item in items) { foreach(var otheritem in otheritems) { if (!double.TryParse(otheritem)) { //break inner loop //continue outer loop so we never get to DoStuff() } } DoStuff(); } 回答1: How about using a flag? foreach(var item in items) { bool flag = false; foreach(var otheritem in otheritems) { if (!double.TryParse(otheritem

Is Regex instance thread safe for matches in C#

送分小仙女□ 提交于 2019-12-10 00:36:30
问题 I have this regex which I am using in a Parallel.ForEach<string> . Is it safe? Regex reg = new Regex(SomeRegexStringWith2Groups); Parallel.ForEach<string>(MyStrings.ToArray(), (str) => { foreach (Match match in reg.Matches(str)) //is this safe? lock (dict) if (!dict.ContainsKey(match.Groups[1].Value)) dict.Add(match.Groups[1].Value, match.Groups[2].Value); }); 回答1: Regex objects are read-only, and therefore are thread safe. It's their returns, the Match objects that could potentially cause

InitializeCulture() on every single page necessary?

我们两清 提交于 2019-12-10 00:00:55
问题 I have a web forms site that needs to be localized. I mean, it is localized, I just need to set the right language according to the domain. Something like: protected override void InitializeCulture() { var i = Request.Url.Host.ToLower(); var domain = i.Substring(i.Length - 2, 2); if (domain == "se") { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("sv-SE"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("sv-SE"); } else if (domain == "dk") { Thread

WCF REST Service Template 40 (CS) sample with data access

99封情书 提交于 2019-12-09 23:57:33
问题 WCF noob here. I am exploring the online template in Visual Studio 2010: WCF REST Service Template 40 Does anyone know of a great sample to learn from? Or at least point me the right direction... I am trying to create a service of looking up a EmployeeID from a database to return some serialized employee profile data. Basically, I wish to know what goes where (via the newer way, WCF 4.0, RESTful, Json). -ConnectionString -QueryString -etc Hoping the Url will look something like this: http:/

IEnumerable not enumerating in foreach

倾然丶 夕夏残阳落幕 提交于 2019-12-09 22:03:00
问题 I'm encountering a problem with one of my IEnumerable 's that I haven't seen before. I have a collection: IEnumerable<IDependency> dependencies; that's being used in a foreach loop. foreach (var dependency in dependencies) For some reason this foreach doesn't iterate over my IEnumerable and simply skips to the end. If I change my foreach to loop through a a list however it seems to work fine: foreach (var dependency in dependencies.ToList()) What could I be doing that's causing this behaviour

Intellisense supported TextBox in WPf

感情迁移 提交于 2019-12-09 17:41:00
问题 I started with wpf 4.0. I have a textBox where i shall enter linq expressions. So i want to enable intellisense support in the textEditor. All i do now is bringing a popUp which has the list of items. Do i have anyother way to do this in WPF. Thanks. 回答1: No, none of the built-in controls provide Intellisense functionality. It's a feature provided by code editors, and I doubt Microsoft intends for you to re-implement Visual Studio. You'll have to write it yourself. See here for a sample:

Code-First Entity Framework inserting data with custom ID

岁酱吖の 提交于 2019-12-09 17:21:42
问题 I am using code-first EF in my project and face issue when the data with custom id is being inserted. When I am trying to insert data with custom ID (for instance 999), EF ignores it and inserts incremented ID into table. My model: public class Address { [Key] public int Id { get; set; } public string FirstName { get; set; } ... } How to solve this probleb? EDIT: 1) How to begin incrementing from N, but not from 0? 2) If I don't specify custom ID, DB must increment and inserts own. If I

Is it possible to adjust AppFabric Cache server to store larger objects?

*爱你&永不变心* 提交于 2019-12-09 16:55:22
问题 I'm getting an error with the AppFabric Cache Server when I presume a larger object graph gets added to the cache. ErrorCode :SubStatus:The connection was terminated, possibly due to server or network problems or serialized Object size is greater than MaxBufferSize on server. Result of the request is unknown. I know for sure its not a network problem. I was able to add a bunch of objects to cache before this particular one. And looking into it, the object is a bit bigger than the others that

Why aren't IStructuralEquatable and IStructuralComparable generic?

放肆的年华 提交于 2019-12-09 16:28:20
问题 System.Collections.IStructuralEquatable and System.Collections.IStructuralComparable were added in .NET 4, but why aren't they generic, like IEquatable<T> and IComparable<T> ? 回答1: The example on MSDN gives part of the answer here; it seems to be useful for heterogeneous equality, rather than homogeneous equality - i.e. for testing whether two objects (/values) of potentially different types should be considered equal. In such scenarios, it is extremely likely that the calling code is dealing

Copy text from word file to a new word

别来无恙 提交于 2019-12-09 16:17:47
问题 I am reading the text from word file and replace some text from the readed text. var wordApp = new Microsoft.Office.Interop.Word.Application(); object file = path; object nullobj = System.Reflection.Missing.Value; var doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); IDataObject data =