## c# – An elegant way to handle Event subscriptions?

If I have a class instance as Property, which has events and changes based on user input (for example, the user selects one from a list), I often find myself doing the following:

``````public MyClass MySelectedInstance
{
get { return mySelectedInstance; }
set
{
if (mySelectedInstance!= null) mySelectedInstance.myEventFired -= DoStuff;
SetProperty<MyClass >(ref mySelectedInstance, value);
if (mySelectedInstance!= null) mySelectedInstance.myEventFired += DoStuff;
}
}
``````

As far as I understand, it is important to unsubscribe from events, so the GC can destroy objects. However, for single instance it is not the biggest of problems, but imagine `MyClass` contains a List of objects with events. Now every time the user would change selection, I have to go through the whole list and handle event subscriptions accordingly.

More often than not, if I find my code solutions not elegant enough, there is already a pattern out there to use. So the question is: How to do this kind of stuff?

## Divi Builder Plugins – Additions to the Elegant Divi Builder

– Fixed a bug that caused animations to remove module design styles such as background colors.
* includes/builder/scripts/frontend-builder-scripts.js

version 2.12.1 ( updated 08-13-2018 )
– Updated translation files.
– Fixed issue with partial support for modules with child modules.
– Fixed playback issues of Facebook videos in the Video module.
– Fixed display issue with Video Module, with animation applied, in when playing the video in fullscreen, in Chrome.
– Fixed fullwidth mobile…

.(tagsToTranslate)nulled(t)nulled sites(t)nulled forum(t)nulled script(t)nulled scripts(t)nulled script forum(t)best nulled scripts site(t)xenforo nulled(t)xenforo 2 nulled(t)xenforo nulled themes(t)seo xenforo 2(t)xenforo themes(t)seo for xenforo(t)vbulletin nulled(t)vbulletin 5 nulled(t)whmcs nulled(t)hexa whmcs(t)whmcs addons nulled(t)whmcs templates nulled(t)whmcs template nulled(t)whmcs modules nulled(t)whmcs themes nulled(t)cs-cart nulled(t)xfilesharing pro nulled(t)blesta nulled(t)arrowchat nulled(t)multi vendor ecommerce script nulled(t)seo providers(t)adsense alternative

## Elegant way of defining a set [closed]

I would like to define a set to express the trading (business) days in a month.
Currently, I write:

Let $$J_i={d ; vert ; d ; text{is an integer, and}: 1leq d leq 31}$$ be the set of trading days in a month $$T_i$$.

Above, I referred to Set-builder notation in Wikipedia, and changed the expression slightly to:

$$J_i={d : vert : d in mathbb{Z}^+ : text{and} : : 1leq d leq 31}$$.

Am I doing right in the second expression?
If there is any room for an improvement, could you please show me how to do it?
Your helps are highly appreciated 🙂

## An “elegant” way of saving data to a database in a .NET C# enviroment dynamically

#### Stack Exchange Network

Stack Exchange network consists of 176 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

## plotting – Two functions in one plot with different y-axis? I solved it by overlapping the two which is not really elegant. Do you have a better idea?

This plots a quite nice figure but there should be a better option?

``````Clear(c,L,(CapitalDelta)(Nu),R)
c=  299792458;
L= 3440*10^(-9);
(CapitalDelta)(Nu)= c/(2L);
R=0.9;
ReflectionCoefficient((Nu)_)= R (Exp(I 2 Pi (Nu) /(CapitalDelta)(Nu) )-1)/(1-R^2 Exp((Nu) I 2Pi /((CapitalDelta)(Nu))));

Phase=Plot(Abs(ReflectionCoefficient((Nu) *c/(2L))),{(Nu),0.5+ 2L/c ,1.5+2L/c},PlotRange->{{0.5,1.5},{-0.1,1.1}},PlotStyle->{Red,Thick},LabelStyle->Directive(Bold,12,Black),FrameLabel->{{"Intensity","Phase in (Degree)"},{"Free Spectral Range",""}},ImagePadding->True,ImageSize->500,Frame-> {True,True,True,True},FrameStyle->{Black,Red,Black,Transparent},FrameTicks->{{All,{{0.025,"-150"}}},{True,True}},FrameStyle -> Directive(22))

Intensity= Plot(Arg(ReflectionCoefficient((Nu) *c/(2L)))*360/(2Pi),{(Nu),0.5+ 2L/c ,1.5+2L/c},PlotRange->{{0.5,1.5},{-190,190}},LabelStyle->Directive(Bold,12,Black),FrameLabel->{{"Intensity","Phase in (Degree)"},{"Free Spectral Range",""}} ,ImagePadding->True,ImageSize->500,Frame->{True,True ,True,True},FrameStyle->{Black,Transparent,Transparent,Blue},FrameTicks->{{{{0,"0.2"},{160,"1.0"}},{{0,"0"},{90,"90"},{180,"180"},{-90,"-90"},{-180,"-180"}}},{True,True}},FrameStyle->Directive(22),PlotStyle->{Thick,Blue})

PowerPlot=Overlay({Intensity,Phase},Alignment->Left)
``````

## Looking for a more elegant C# solution for my registry class

My code writes, reads, and removes program settings in the registry. I’m using Visual Studio 2019 and my target Framework is .NET Framework 4.8.

I’m looking for more elegant functions.
Is there error handling I missed in these functions?
How can I optimize the code?

Please provide an example, so that I can learn.

I have the following functions at the moment:

``````public static class Settings
{

public static void SaveSetting(string sCompanyName, string sAppName, string sSection, string sValueName, string sValue)
{
RegistryKey softKey = Registry.CurrentUser.OpenSubKey("Software", true);
RegistryKey compKey = softKey.CreateSubKey(sCompanyName);
RegistryKey appKey = compKey.CreateSubKey(sAppName);
RegistryKey secKey = appKey.CreateSubKey(sSection);
secKey.SetValue(sValueName, sValue);
}

public static string GetSetting(string sCompanyName, string sAppName, string sSection, string sValueName, string sDefault)
{

RegistryKey softKey = Registry.CurrentUser.OpenSubKey("Software", true);
RegistryKey compKey = softKey.CreateSubKey(sCompanyName);
RegistryKey appKey = compKey.CreateSubKey(sAppName);
RegistryKey secKey = appKey.CreateSubKey(sSection);

return (string)secKey.GetValue(sValueName, sDefault);
}

public static void DeleteSetting(string sCompanyName, string sAppName, string sSection, string sValueName)
{
RegistryKey softKey = Registry.CurrentUser.OpenSubKey("Software", true);
RegistryKey compKey = softKey.CreateSubKey(sCompanyName);
RegistryKey appKey = compKey.CreateSubKey(sAppName);
RegistryKey secKey = appKey.CreateSubKey(sSection);

if (secKey.GetValue(sValueName) != null)
{
secKey.DeleteValue(sValueName);
}

}

}
``````

## I Created a Template Animated Videos for You, Click Order Now! for \$109

No need to bother looking for animated videos to advertise your business. We created animated videos tempalate for you at low prices and the best quality. Video Render at 1080p.

by: Rizkianwar
Created: —
Category: Video
Viewed: 1

.

## c – Elegant way to check return of getXY() for multiple values in conditional check

When I want to execute some code under the condition that a variable has one of two (or more) values I can use the OR operator:

``````if (var == x || var == y) {
DoSomething();
}
``````

But I’m not sure whether I should do this directly, when var is a getXY function, that might even include some expensive checks:

``````// Is this good style?
if (getXY() == x || getXY() == y) {
DoSomething();
}
``````

Is there some specified behaviour whether or not the compiler is optimizing these two function calls to only one for both checks? Or is this implementation specific and I have to check for each case?

Would it be “better” to do the function call first, store the result in var and then do the check on var? What is in general considered good coding style for this?

``````// Or should I do the check first?
var = getXY();
if (var == x || var == y) {
DoSomething();
}
``````

I’m programming in C, but I would assume this to be a general consideration similar in most languages.

## javascript – shorter or more elegant code for if else conditions

I have the following if-else block, but I feel like there is a much better way this code could be written. Like shorter code or at least a bit more elegant.

``````movement(_b) {

let centerOfPaddle = this.y + this.height / 2;

if (centerOfPaddle < _b.y - 80) {
this.y += 4
}
else if (centerOfPaddle > _b.y + 80) {
this.y -= 4
}
else if (centerOfPaddle < _b.y - 60) {
this.y += 2
}
else if (centerOfPaddle > _b.y + 60) {
this.y -= 2
}
else if (centerOfPaddle < _b.y - 40) {
this.y += 1
}
else if (centerOfPaddle > _b.y + 40) {
this.y -= 1
}
else if (centerOfPaddle < _b.y - 20) {
this.y += 0.5
}
else if (centerOfPaddle > _b.y + 20) {
this.y -= 0.5
}

}
``````

Any suggestions will be much appreciated.

## co.combinatorics – Do you know an elegant proof for this expression for a Schur function?

I would like to suggest an interpretation using super symmetric functions. These are symmetric functions that are symmetric in two sets of variables $${x_i}$$ and $${y_j}$$ separately. They satisfy the property that setting a single $$x_i$$ variable to equal $$z$$ and a single $$y_j$$ variable equal to $$z$$ gives a polynomial independent of $$z$$, in addition to several other conditions (see Chapter 1, Section 3, Exercise 23 of Macdonald’s book). Note that since it’s independent of $$z$$, it’s the same as just setting $$x_i = y_j = 0$$, which amounts to considering the same super symmetric function in a smaller set of variables.

A concrete description of supersymmetric functions is as follows. The supersymmetric functions are the image of the map $$Lambda to Lambda otimes Lambda$$ given by $$(mathrm{Id} otimes S) circ Delta$$, where $$Lambda$$ is the ring of symmetric functions, $$Delta$$ is the usual comultiplication, and $$S$$ is the usual antipode (which sends the power sum $$p_i(y)$$ to $$-p_i(y)$$). The variables in the second factor (i.e. $${y_j}$$) are the “super variables”. Because the map is injective, the supersymmetric functions are abstractly isomorphic to $$Lambda$$, but they are convenient for performing certain specialisation tricks. But let me give an example:
$$sum_{r=0}^infty e_r(x/y) t^r = frac{prod_i(1+x_i t)}{prod_j (1+y_j t)}.$$
These are the elementary super symmetric functions. You can see that if you set a single $$x_i = z$$ and a single $$y_j = z$$, then a factor of $$1+zt$$ cancels in the numerator and denominator, giving an expression independent of $$z$$ as stated above. Another example is that $$p_i(x/y) = p_i(x) – p_i(y)$$.

Now we’re in a situation where we can explain the identity. Clearly $$s_{mu}(x) = s_mu(x,1/1)$$ by the specialisation property of super symmetric functions. But the right hand side can be obtained by first setting an $$x_i$$ equal to 1, then passing from $$Lambda$$ to super symmetric functions, then setting a $$y_j=1$$ and all other $$y$$‘s to zero (that setting $$x_i=1$$ commutes with passing to super symmetric functions isn’t totally obvious, but I’m omitting it for the sake of brevity). The upshot of this is that $$s_mu(x,1) = sum_lambda s_lambda(x) s_{mu/lambda}(1)$$, and $$s_{mu/lambda}(1)$$ is zero unless $$mu/lambda$$ is a horizontal strip. This gives the outer sum in your expression. Then we recognise that second part of the operation replaces $$p_i(x)$$ with $$p_i(x/1) = p_i(x) – p_i(1) = p_i(x)-1$$, which recovers your expression, where I have taken for granted that
$$s_lambda(x) = sum_{alpha vdash |lambda|} frac{chi_alpha^lambda}{z_alpha}prod_i p_i^{a_i}.$$