Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

2

So why create a nested class? I can think of couple of important reasons: 1. Enable encapsulation Many times nested classes are implementation details of the class. Users of the main class should not have to care about their existence. You should be able to change them at will without requiring the users of the main class to change their code. 2. Avoid ...


0

Nested Class can be used whenever you want to create more than once instance of the class or whenever you want to make that type more available. Nested Class increases the encapsulations as well as it will lead to more readable and maintainable code.


0

I use public nested classes for related helper classes. public class MyRecord { // stuff public class Comparer : IComparer<MyRecord> { } public class EqualsComparer : IEqualsComparer<MyRecord> { } } MyRecord[] array; Arrays.sort(array, new MyRecord.Comparer()); Use them for related variations. // Class that may or may not ...


1

There are three separate issues at play; and in order to answer your question, I need to address all three issues. Custom Application Exceptions should be for exceptional events, and not errors that are not exceptional events. Think of an invalid user input. Users getting input wrong is not exceptional; and shouldn't be treated as such. A hostile user ...


0

You are assuming the C# compiler and IDE are or should be aware of what you are doing and to what purpose. They don't, C# is a third generation programming language. OK, you get a template because you told the IDE you are doing a WPF application or a Windows Forms application, that will give you a head start and some guidance. But knowing which operations ...


4

why isn't it automatic and behind the scenes. This would work as long as there is only one action for one property of one component is involved, but as soon as there are more actions, maybe actions which are dependent on each other, one would have a high risk of running into race conditions. The explicit "Invoke" mechanics works like a transactional bracket ...


1

For thread safety: the threading apartment used by WPF controls is STA, which only allows the thread which created the components to modify them. This is done to increase thread safety on objects that are not inheritly thread safe. Changing something on a background thread might indicate a threading error on behalf of the programmer, hence the exception and ...


2

If your program wants to update the UI from a non-UI thread, the application framework has two choices: block the non-UI thread until the UI thread is waiting for events, then lock out the UI thread until the non-UI thread has done its update. let the non-UI thread specify the update as a deferred action, i.e. some code that can be executed by the UI thread ...


0

For the sake of illustration, let's say that the classes you need to register depend on a type called IConfigurationValues. It could be an interface or a concrete type. You can pass the configuration values to your module as a constructor argument like this: public class MyModule : Autofac.Module { private readonly IConfigurationValues _configuration;...


3

Some things to think about: Creating the IoC container need not be the first thing you do. In fact, reading configuration should generally happen first, partially because other aspects of the IoC configuration might depend on that too. For example, maybe your configuration lets you switch between completely different data sources, that therefore require ...


1

I've run into similar problems with wanting to use a TryParse/Convert/etc. method where I sometimes need to know how and why it failed. I ended up taking inspiration from how some serializers handle errors and using events. This way the syntax for my TryX(..., out T) method looks as clean as any other and reliably returns a simple false as the pattern ...


Top 50 recent answers are included