Browsing 7239 questions and answers with Jon Skeet
Can I declare an Interface (i.e. IMySpecialControl) that requires classes implementing it to also inherit from some base class (i.e. System.Windows.Controls.UserControl)? No, there's nothing in C# which defines that. It would... more 12/10/2013 6:00:01 PM
An int has 32 bits. The byte will take 8 bits. That leaves you 24 bits to play with - enough for one and a half char values, uncompressed. Unless you really only need to store single character strings, or you have a restricted range of... more 12/10/2013 5:35:35 PM
Is there a way to set my property as null or string.empty in order to restablish the field in the database as null. No. Because it's non-nullable. If you want it to be nullable, you have to use Nullable<Guid> - if you didn't,... more 12/10/2013 5:24:41 PM
Well I wouldn't put the Console.WriteLine in a lambda expression, but you can use SelectMany to avoid the nesting: foreach (var add in testList.SelectMany(x => x.addressList)) { Console.WriteLine(add.name); } I see little reason... more 12/10/2013 5:13:00 PM
It's easiest just to use a lambda expression: private void doWork() { // Name changed to avoid it being a keyword MyClass clazz = new MyClass(); clazz.StatusChanged += (sender, args) => { string message = (string)... more 12/10/2013 4:30:35 PM
You have at least two problems: Math.Floor will return a double or decimal; you're trying to assign it to an int variable Your divisions are being performed in integer arithmetic, which is presumably not what you were intending given... more 12/10/2013 4:11:52 PM
I suspect you actually want: var query = xdoc.Root.Descendants("VM") .Where(vm => (string) vm.Attribute("name") == systemName) .Descendants("vmClient") .Select(vmClient => (string)... more 12/10/2013 2:55:49 PM
Either move the level variable (which should probably be an instance variable, rather than a static variable) to Buildings or make getLevel() abstract so that each subclass has to implement it separately (whether that's by returning a... more 12/10/2013 2:25:18 PM
Just use: myLunch = new ChocolateBar(); or myLunch = default(ChocolateBar); These are equivalent1, and will both end up assigning a new "all fields set to zero" value to myLunch. Also, ideally don't use mutable structs to start with... more 12/10/2013 1:38:35 PM
This: public Image[][][] cardImages = new Image[9][][]; ... creates a top level array with 9 elements in. Every element value is null. You need: for (int i = 0; i < cardImages.Length; i++) { cardImages[i] = new Image[???][]; //... more 12/10/2013 1:28:35 PM