.NET - Replacing nested using statements with single using statement
Tag : chash , By : Scott Everts
Date : March 29 2020, 07:55 AM
should help you out You need the separate using statements. In your second example, only the BinaryReader will get disposed, not the objects used to construct it. {
var reader = new BinaryReader(((HttpWebResponse)request.GetResponse()).GetResponseStream());
try
{
// do something with reader
}
finally
{
if (reader != null)
((IDisposable)reader).Dispose();
}
}
|
When multiple calls to the same UDF are in a single statement, how many times will it be called?
Date : March 29 2020, 07:55 AM
This might help you This isn't guaranteed. You would need to check the execution plan to find out. Some examples. CREATE FUNCTION dbo.FUNC1(@p1 int)
RETURNS int
AS
BEGIN
RETURN @p1 + 1
END
GO
CREATE FUNCTION dbo.FUNC2(@p1 int)
RETURNS int
WITH SCHEMABINDING
AS
BEGIN
RETURN @p1 + 1
END
GO
SELECT
OBJECTPROPERTYEX(OBJECT_ID('dbo.FUNC1'), 'IsDeterministic'),
OBJECTPROPERTYEX(OBJECT_ID('dbo.FUNC2'), 'IsDeterministic')
GO
SELECT
dbo.FUNC1(number) AS FUNC1,
dbo.FUNC2(number) AS FUNC2
FROM master..spt_values
WHERE dbo.FUNC1(number) >= 5 AND dbo.FUNC2(number) >= 5
ORDER BY dbo.FUNC1(number), dbo.FUNC2(number)
|--Sort(ORDER BY:([Expr1003] ASC, [Expr1004] ASC))
|--Compute Scalar(DEFINE:([Expr1003]=[test].[dbo].[FUNC1]([master].[dbo].[spt_values].[number])))
|--Filter(WHERE:([test].[dbo].[FUNC1]([master].[dbo].[spt_values].[number])>=(5) AND [Expr1004]>=(5)))
|--Compute Scalar(DEFINE:([Expr1004]=[test].[dbo].[FUNC2]([master].[dbo].[spt_values].[number])))
|--Index Scan(OBJECT:([master].[dbo].[spt_values].[ix2_spt_values_nu_nc]))
SELECT
FUNC1,
FUNC2
FROM master..spt_values
CROSS APPLY (SELECT dbo.FUNC1(number), dbo.FUNC2(number)) C(FUNC1, FUNC2)
WHERE FUNC1 >= 5 AND FUNC2 >= 5
ORDER BY FUNC1, FUNC2
|--Sort(ORDER BY:([Expr1003] ASC, [Expr1004] ASC))
|--Filter(WHERE:([Expr1003]>=(5)))
|--Compute Scalar(DEFINE:([Expr1003]=[test].[dbo].[FUNC1]([master].[dbo].[spt_values].[number])))
|--Filter(WHERE:([Expr1004]>=(5)))
|--Compute Scalar(DEFINE:([Expr1004]=[test].[dbo].[FUNC2]([master].[dbo].[spt_values].[number])))
|--Index Scan(OBJECT:([master].[dbo].[spt_values].[ix2_spt_values_nu_nc]))
SELECT
FUNC1 + 10,
FUNC2 + 10
FROM master..spt_values
CROSS APPLY (SELECT dbo.FUNC1(number), dbo.FUNC2(number)) C(FUNC1, FUNC2)
WHERE FUNC1 >= 5 AND FUNC2 >= 5
ORDER BY FUNC1, FUNC2
|--Compute Scalar(DEFINE:([Expr1005]=[Expr1003]+(10)))
|--Sort(ORDER BY:([Expr1003] ASC, [Expr1004] ASC))
|--Filter(WHERE:([Expr1003]>=(5)))
|--Compute Scalar(DEFINE:([Expr1003]=[test].[dbo].[FUNC1]([master].[dbo].[spt_values].[number])))
|--Filter(WHERE:([Expr1004]>=(5)))
|--Compute Scalar(DEFINE:([Expr1004]=[test].[dbo].[FUNC2]([master].[dbo].[spt_values].[number]), [Expr1006]=[test].[dbo].[FUNC2]([master].[dbo].[spt_values].[number])+(10)))
|--Index Scan(OBJECT:([master].[dbo].[spt_values].[ix2_spt_values_nu_nc]))
|
Turning a nested PHP if statement into a single if statement
Tag : php , By : Matt Logan
Date : March 29 2020, 07:55 AM
it helps some times You're checking variable $gender before you assign value to it. Following will help, $gender = isset($_REQUEST['gender']) ? $_REQUEST['gender'] : "";
if ($gender == 'M')
{
echo '<p><b>Good day, Sir!</b></p>';
}
else if($gender == 'F')
{
echo '<p><b>Good day, Madam!</b></p>';
}
else if (!empty($gender) && ($gender != 'M' || $gender != 'F'))
{ // Unacceptable value.
echo '<p class="error">Gender should be either "M" or "F"!</p>';
}
else
{
echo '<p class="error">You forgot to select your gender!</p>';
}
|
Creating a single regex rather than a nested statement
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I want to do the following match: , You can use following regex with modifier i for ignoring the case : ^(?:(?!ref).)*(?=MBzz)(?:(?!ref).)*$
regex=re.compile(r'^[^ref]*(?=MBzz)[^ref]*$',re.I|re.MULTILINE)
^(?:(?![rR][eE][fF]).)*(?=MBzz)(?:(?![rR][eE][fF]).)*$
|
Unity3D Only single if statement being called
Tag : chash , By : Chris Woods
Date : March 29 2020, 07:55 AM
hop of those help? Ok without knowing where PlayBuzzer() is called and if level is increased before or after that, finding the problem is really hard. Did you debug the program? anyway I took the freedom to shorten your function, in order to follow the DRY principle: private void PlayBuzzer()
{
GetComponent<AudioSource>().PlayOneShot(buzzer);
timeRemaining -= 1;
endPanel.SetActive(true);
var scores = new List<int> { 15, 35, 45, 70, 120, 160 };
var mustRestart = PlayerScore.score < scores[level - 1];
GameObject.Find("Restart").SetActive(mustRestart);
GameObject.Find("Continue").SetActive(!mustRestart);
Time.timeScale = 0;
}
|