c#-3.0

Getting “This method or property cannot be called on Null values” error

时光总嘲笑我的痴心妄想 提交于 2019-12-22 09:00:14
问题 UPDATE 1: The exception is being thrown on this line: client_group_details.Add(new ClientGroupDetails( ORIGINAL QUESTION: I have the following code which I have stripped down from 30 columns of data from the database to just 2 columns from the database. I get an error whenever any of the columns return a NULL value: public class ClientGroupDetails { public String Col2; public String Col3; public ClientGroupDetails(String m_Col2, String m_Col3) { Col2 = m_Col2; Col3 = m_Col3; } public

ASP.NET C# Active Directory - See how long before a user's password expires

蹲街弑〆低调 提交于 2019-12-22 07:54:52
问题 I have an interesting problem, I am writing a password management webpage/service and I am trying to find a way to determine when a user's password is going to expire so I can manually reset their other passwords with it and send out an email, etc. The problem I'm having is that when trying to loop through my users I'm getting the bulk of them not having a pwdlastset attribute so I can't determine when it's going to expire. So I guess I am looking for ideas on a good way to check for when a

set Enums using reflection

非 Y 不嫁゛ 提交于 2019-12-22 07:03:17
问题 How to set Enums using reflection, my class have enum : public enum LevelEnum { NONE, CRF, SRS, HLD, CDD, CRS }; and in runtime I want to set that enum to CDD for ex. How can I do it ? 回答1: public class MyObject { public LevelEnum MyValue {get;set,}; } var obj = new MyObject(); obj.GetType().GetProperty("MyValue").SetValue(LevelEnum.CDD, null); 回答2: Try use of class Enum LevelEnum s = (LevelEnum)Enum.Parse(typeof(LevelEnum), "CDD"); 回答3: value = (LevelEnum)Enum.Parse(typeof(LevelEnum),"CDD");

Page_Load not firing in UserControl

喜你入骨 提交于 2019-12-22 06:38:31
问题 I have created a class in c# inside a class library and i have added this control to the default.aspx, but my code doesnt fire the page_load event. Here is the code: What am i doign wrong? The page loads but doesn't show the label on the page. I have added the control to the page correctly without any errors. I have event added the register tag in there. html tag: <RandoIntegerControls:RandomIntegerControl ID="RandomIntegerControl1" runat="server"></RandoIntegerControls:RandomIntegerControl>

Environment.CurrentDirectory in C#.NET

风流意气都作罢 提交于 2019-12-22 05:03:29
问题 The property Environment.CurrentDirectory always returns the path of system directory instead my application directory. In my colleague's PC, it returns application directory. What is the problem? How can I solve it? The following code is working for me ePCRSettings = XMLParser.XmlParser.Deserialize<PCRGeneratorSettings>(string.Format("{0}\\ePCRPDFSettings.xml", AppDomain.CurrentDomain.BaseDirectory)); AppDomain.CurrentDomain.BaseDirectory - Returns the directory E:\MyApplications\. The

Algorithm to visit all points in a matrix of N (unknown) dimensions

喜夏-厌秋 提交于 2019-12-22 01:21:27
问题 I have a multidimensional matrix that can have any number of dimensions greater than one. Looking for an efficient algorithm that can visit every point in the matrix. Some info about the code: The matrix has value accessors like (although these aren't really relevant). object value = matrixInstance.GetValue(int[] point); matrixInstance.SetValue(object value, int[] point); Note: Argument point is array of indexes and must match # of dimensions or an exception is thrown. Information about the

Removing line breaks using C#

守給你的承諾、 提交于 2019-12-21 08:07:28
问题 I am getting a string from database field named 'Description' and it has line breaks. It looks like this: Header of Items Description goes here.This the description of items. How can I remove the line breaks. I tried following function but It is not working: public string FormatComments(string comments) { string result = comments.Replace(@"\r\n\", ""); result = result.Replace(" ", ""); return result; } Please suggest solution. Regards, Asif Hameed 回答1: The primary reason is that you are using

How to calculate the sum of all values in a dictionary excluding the first item's value?

烈酒焚心 提交于 2019-12-21 07:08:07
问题 I have a dictionary of (string, decimal) and need to calculate the sum of all the Values (decimal values) starting from the second item. Is it achievable using LINQ? 回答1: Very achievable using LINQ: myDict.Skip(1).Sum(x => x.Value); However, the standard Dictionary class doesn't guarantee ordering of items, so the "first" item can be anything. 回答2: Why not just sum them all up, then subtract the first item? myList.Sum(x => x.Value) - myList.First().Value; 回答3: Easy enough to do using LINQ:

What is datetime2?

丶灬走出姿态 提交于 2019-12-21 06:47:44
问题 I´ve got this in a INSERT statment to MSSQL 2008 System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. 回答1: Defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision. http://technet.microsoft.com/en-us/library

Using C# params keyword in a constructor of generic types

混江龙づ霸主 提交于 2019-12-21 04:19:08
问题 I have a generic class in C# with 2 constructors: public Houses(params T[] InitialiseElements) {} public Houses(int Num, T DefaultValue) {} Constructing an object using int as the generic type and passing in two ints as arguments causes the 'incorrect' constructor to be called (from my point of view). E.g. Houses<int> houses = new Houses<int>(1,2) - calls the 2nd construtor. Passing in any other number of ints into the constructor will call the 1st constructor. Is there any way around this