c#-4.0

xdocument descendantsnodes vs nodes

好久不见. 提交于 2021-01-29 18:14:18
问题 I'm trying to understand the difference between the extension method, DescendantsnNodes and the method, "Nodes" of the class XDocument. I can see that the DescendantsNodes should return all descendants of this document or element and Nodes should return all child nodes of this document or element. I don't understand what's the difference between "all child nodes" and "all descendants". could someone please clarify this? 回答1: A child node would be a node which is directly "underneath" a

disabling a button on form 2 from form 1 with a checkbox

僤鯓⒐⒋嵵緔 提交于 2021-01-29 18:06:23
问题 I have two form objects: form1 and form2 . I have 1 button on form2 and a check box on form1 . When the check box is checked, I want to show the button and when it is unchecked I want the button to be disabled. I know that in visual basic I did such a thing like this: form2.button.visible = false How would I do something like this in c# ? 回答1: In general case (when Form1 and From2 instances are independent) you can do something like that. In Form2 implement a public property : public partial

WPF UserControl loading dynamically based on which button is clicked

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 07:03:42
问题 I am very new to WPF and this is my 1st application. I have a Ribbon with different buttons. I want to load a UserControl based on which button is clicked. I have a button called "Change Password" and I created the UserControl that will represent the UI to change the password. I have another button called "Unlock Account" and I have a UserControl that can unlock an account. App --> Ribbon --> RibbonButton --> SwappableUserControlAtRunTime I want to use the same space in my Window to load

How to set height and width of a new window from code behind

房东的猫 提交于 2021-01-28 18:51:55
问题 I have been trying this from hours that I am opening a new window and I am bound to launch from code behind so it is not opening in new tab. I want to adjust the height and width of this window, but I am unable to set the same. I also tried calling a javascript function from code behind and writing the same in aspx page, but no luck. I am posting my code: From Code behind: Page.ClientScript.RegisterStartupScript(typeof(string), scriptKey, "<script type='text/javascript'>window.open('..

Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'

荒凉一梦 提交于 2021-01-28 05:05:57
问题 I'm getting the above error when trying to test on upload to FTP. But when I'm trying run this code from my local machine, it is giving error. Kindly advise. Here my code below : static void Main(string[] args) { var yourListOfFilePaths = Directory.GetFiles(filepath); using (ZipFile zip = new ZipFile()) { foreach (string filePath in yourListOfFilePaths) { zip.AddFile(filePath); // FILE PATH LOCATION / WHICH FOLDER FILES YOU WANTED TO ZIP zip.Password = "abc1234"; // CHANGE YOUR PASSWORD HERE

The type 'X' is not mapped as a Table

烈酒焚心 提交于 2021-01-28 04:04:31
问题 I have ADO.NET Entity Data Model for my tables and if I use it directly it works fine. I wanted to write a wrapper, so that I don't have to repeat the same code again. Ended up writing some DataContext Extension methods. So, have something like this to get Data from the Table. public static TEntity Get<TEntity>(this DataContext dataContext, object id, string primaryKeyName) where TEntity : class, new() { if (id == null) return new TEntity(); var table = dataContext.GetTable<TEntity>(); return

Winforms - Invoking a method in another thread

五迷三道 提交于 2021-01-27 19:24:22
问题 What is the best practice to invoke a method in a different thread from a winform button so the ui doesn't freeze or creates a delay? 回答1: In a first step start with BackgroundWorker If this doesn't meet your requirements or you need more advanced stuff you should take a look into one of these: Task Parallel Library ReactiveExtensions async / await 回答2: Invoke((MethodInvoker) delegate { DoSomething(); }); 回答3: You should call Control.Invoke or BeginInvoke , see in-depth reference here. 回答4:

Why does System.Buffer.BlockCopy take int instead of long?

纵然是瞬间 提交于 2021-01-27 18:12:48
问题 Is there a reason System.Buffer.BlockCopy takes int parameters instead of long for the offset/length of the copy? Streams generally work with long , why would BlockCopy not have an overload that takes long , too? 回答1: Because prior to .NET 4.5, no object could exceed 2 gigabytes. So there was no reason to have more than an int to represent the length. Even in .NET 4.5, although an array can be more than 2 gigabytes in length, it can't have more than 2^31 items. So the maximum size of a byte[]

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

我的梦境 提交于 2021-01-27 16:06:00
问题 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,

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

懵懂的女人 提交于 2021-01-27 16:04:31
问题 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,