c#-4.0

Difference between LINQ FirstOrDefault vs. Where(…).FirstOrDefault?

a 夏天 提交于 2021-01-27 15:51:55
问题 What difference between FirstOrDefault(someField => someField.Name.Equals(settings.Text)) and Where(someField => someField.Name.Equals(settings.Text)).FirstOrDefault() ? As far as I understand in both cases Linq will run till the first occurence that suits the condition. 回答1: If we are talking about Linq to Objects, then there is one notable difference. Second statement Where(someField => someField.Name.Equals(settings.Text)).FirstOrDefault() Will create WhereEnumerableIterator internally,

Custom color for ICellStyle FillForegroundColor than provided named colors

旧城冷巷雨未停 提交于 2021-01-26 12:38:50
问题 We are newly started using NPOI components. We are having issues to set FillForegroundColor of ICellStyle property. ICellStyle HeaderCellStyle = xssfworkbook.CreateCellStyle(); HeaderCellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.RED.index; FillForegroundColor expects of type short. How do we set a different color rather than using colors in HSSFColor. We need to set to "RGB192:0:0" and how do we do that for ICellStyle property FillForegroundColor Colud someone help us by some

Get posted file over HTTP Listener in c#

给你一囗甜甜゛ 提交于 2021-01-04 04:16:01
问题 I have make a simple http server using c#. And I know how to get posted data and output them. Here is my c# code public static void start(){ HttpListener listener = new HttpListener(); listener.Prefixes.Add(new Uri("http://localhost:8080").ToString()); istener.Start(); while(true){ HttpListenerContext con = listener.GetContext(); showPostedData(con.Request); con.Response.StatusCode = (int)HttpStatusCode.NotFound; string data = "Uploaded successful"; byte[] output = Encoding.ASCII.GetBytes

Get posted file over HTTP Listener in c#

余生颓废 提交于 2021-01-04 04:13:50
问题 I have make a simple http server using c#. And I know how to get posted data and output them. Here is my c# code public static void start(){ HttpListener listener = new HttpListener(); listener.Prefixes.Add(new Uri("http://localhost:8080").ToString()); istener.Start(); while(true){ HttpListenerContext con = listener.GetContext(); showPostedData(con.Request); con.Response.StatusCode = (int)HttpStatusCode.NotFound; string data = "Uploaded successful"; byte[] output = Encoding.ASCII.GetBytes

How to remove a single, specific object from a ConcurrentBag<>?

戏子无情 提交于 2020-12-27 11:10:23
问题 With the new ConcurrentBag<T> in .NET 4, how do you remove a certain, specific object from it when only TryTake() and TryPeek() are available? I'm thinking of using TryTake() and then just adding the resulting object back into the list if I don't want to remove it, but I feel like I might be missing something. Is this the correct way? 回答1: The short answer: you can't do it in an easy way. The ConcurrentBag keeps a thread local queue for each thread and it only looks at other threads' queues

How to remove a single, specific object from a ConcurrentBag<>?

爱⌒轻易说出口 提交于 2020-12-27 11:09:17
问题 With the new ConcurrentBag<T> in .NET 4, how do you remove a certain, specific object from it when only TryTake() and TryPeek() are available? I'm thinking of using TryTake() and then just adding the resulting object back into the list if I don't want to remove it, but I feel like I might be missing something. Is this the correct way? 回答1: The short answer: you can't do it in an easy way. The ConcurrentBag keeps a thread local queue for each thread and it only looks at other threads' queues

Why is an ExpandoObject breaking code that otherwise works just fine?

久未见 提交于 2020-12-27 08:28:12
问题 Here's the setup: I have an Open Source project called Massive and I'm slinging around dynamics as a way of creating SQL on the fly, and dynamic result sets on the fly. To do the database end of things I'm using System.Data.Common and the ProviderFactory stuff. Here's a sample that works just fine (it's static so you can run in a Console): static DbCommand CreateCommand(string sql) { return DbProviderFactories.GetFactory("System.Data.SqlClient") .CreateCommand(); } static DbConnection

Is there an equivalent for Delphi's “with” command in c#?

ぐ巨炮叔叔 提交于 2020-12-26 05:54:30
问题 I was wondering if there is a command in C# which I can use like with command in Delphi? // like this : with(textbox1) { .text="some text as text of text box"; .tag=1231; } // in Delphi with edit1 do begin text="some text as text of edit1"; tag=1231; end; 回答1: Not for already created instances. However, when you create a new instance you can do: var textbox1 = new Textbox { Text = "some text as text of text box", Tag = 1231 }; 回答2: No, that does not exist in C#. 回答3: No, it does not exist in

Is there an equivalent for Delphi's “with” command in c#?

我只是一个虾纸丫 提交于 2020-12-26 05:52:06
问题 I was wondering if there is a command in C# which I can use like with command in Delphi? // like this : with(textbox1) { .text="some text as text of text box"; .tag=1231; } // in Delphi with edit1 do begin text="some text as text of edit1"; tag=1231; end; 回答1: Not for already created instances. However, when you create a new instance you can do: var textbox1 = new Textbox { Text = "some text as text of text box", Tag = 1231 }; 回答2: No, that does not exist in C#. 回答3: No, it does not exist in

Is there an equivalent for Delphi's “with” command in c#?

寵の児 提交于 2020-12-26 05:51:48
问题 I was wondering if there is a command in C# which I can use like with command in Delphi? // like this : with(textbox1) { .text="some text as text of text box"; .tag=1231; } // in Delphi with edit1 do begin text="some text as text of edit1"; tag=1231; end; 回答1: Not for already created instances. However, when you create a new instance you can do: var textbox1 = new Textbox { Text = "some text as text of text box", Tag = 1231 }; 回答2: No, that does not exist in C#. 回答3: No, it does not exist in