|
It makes perfect sense. I just changed my comment to the wrong Mehdi's post and stated: abstract class is not a placeholder, not even close. I explained what it is and what is its purpose. And it should add: it should not be used as a substitute of interface.
Having non-abstract methods in an abstract class has more than perfect sense. Such methods are inherited and can be used in derived classes (so they should better be protected). Internal and public methods are even more important: the compile-time type of abstract class is usually used as a base class for some hierarchy of terminal derived classes used in polymorphic set. This is how you work with derived classed: through members of the base class. If such base class method uses virtual methods, late binging mechanism dispatch the calls to the methods of derived classes, so the whole OOP mechanism is leveraged.
There are many cases when this method in abstract class need not to be overridden, therefore, there is no a need to make it virtual or abstract (all abstract methods are of course virtual).
This is the very basic approach in OOD every developer should know and use.
[EDIT]
Now, let me explain why there is no danger in your assignment of the abstract property in a non-abstract (and even non-virtual) method NoImplementations :
This is an instance method. As an instance method, it will need an instance to be called on. Such instance will always be an instance of some derived non-abstract type, because an abstract type won't allow to get an instance. And, such non-abstract type could not be created if SomeInt is not given the implementation. The mechanism of the late binding will use the virtual method table for the setter of SomeInt , according to the runtime type of that non-abstract derived type. Therefore, in all cases where NoImplementations can be called, the setter of SomeInt can also be correctly called and actually assign the property value. No problems whatsoever.
—SASergey A Kryukov
modified 10-Nov-14 17:39pm.
|
|
|
|
|
Countered Univote.
What do you get when you cross a joke with a rhetorical question?
---
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
|
|
|
|
|
Counter countered.
That's how democracy works
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, as soon as you ready to agree with your role of the person which wrong action can be compensated by other public.
You did not even explain your opinion.
Voter always right?
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: You did not even explain your opinion. You don't get an explanation with each vote.
Sergey Alexandrovich Kryukov wrote: Voter always right? Ehr, again; "no".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Of course not. But you decided to write and motivate your vote. You wrote, but not motivated, that's all. And you didn't understand the matter. Look, I don't have problem with you. But I would advise you to understand that everyone can read what you write.
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: You wrote, but not motivated, that's all. That would be a waste of time, just as the rest of this thread is.
Sergey Alexandrovich Kryukov wrote: And you didn't understand the matter. That is your assessment.
Sergey Alexandrovich Kryukov wrote: I would advise you to understand that everyone can read what you write. I don't mind
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: This is the very basic approach in OOD every developer should know and use. I'm gonna suffice with a "No".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
So what? Do you understand that you have confessed in your own ignorance?
If some statement makes you feel bad, it does not make this statement false. Any objections? Only, please, on the matter of the subject under the discussion.
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: Do you understand that you have confessed in your own ignorance? By not agreeing with you?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
No, not by not agreeing with me.
—SASergey A Kryukov
|
|
|
|
|
Give up; you'll never win. It's like punching jelly (or jello if you speak American)
|
|
|
|
|
I'm trying to find the nearest number that divides evenly into a pre-defined number.
Examples:
x = 12700000 / y where y is the given number and x is the nearest number that divdes into 12700000 evenly.
y = 6250, x = 6250 (12700000 / 6250 = 2032)
y = 6350, x = 6350 (12700000 / 6350 = 2000)
y = 6260, x = 6250 (12700000 / 6260 = 2028.753994)
y = 6301, x = 6350 (12700000 / 6301 = 2015.553087)
Is there a way to do this using C#?
I'm sorry I didn't explain myself correctly. I have edited the question above.
modified 10-Nov-14 9:10am.
|
|
|
|
|
Member 11220952 wrote: Is there a way to do this using C#? Of course, that's what programming languages are for. Now what part of dividing one number into another are you having problems with?
|
|
|
|
|
In the examples you show, the .NET compiler is doing exactly what you tell it, and assuming you are using the 'Double Type, the two results you think are incorrect, are correct.
I think you have not clearly expressed what you want here; I'd guess you want:
1. ? to take two numbers and return true/false if the first number is integrally divisible by the second number.
2. ? using the same two numbers: return the nearest value to the second value that can integrally divide the first number
3. ? or ... maybe you want to return the integral dividend it the division is integral, but return the closest value that can integrally divide if the division is not integral ?
Try and restate exactly what you want, and I'm sure you'll get a helpful response.
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
Check out the modulus % operator for this.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
This is just off the top of my head and admittedly not very performant.
int num = 12700000;
int answer = num;
while (--answer > 1) {
if (num % answer == 0) {
break;
}
}
Console.WriteLine ((answer > 1 ) ?
string.Format ("The largest number that divides {0} is {1}.", num, answer) :
string.Format ("Sorry, {0} is a prime number.", num));
}
/ravi
|
|
|
|
|
Here's an idea based on the idea that your problem is one of finding the nearest prime divisor of integer 'n by integer 'd:
private bool findNearestPrimeDivisor(int n, int d, out int? result)
{
int mod = n % d;
if (mod == 0)
{
result = null;
return true;
}
bool primeFound = false;
int prime = 0;
for (int i = mod; i < d + mod; i++)
{
if (n % i == 0)
{
primeFound = true;
prime = i;
if (i > d) break;
}
}
if (primeFound)
{
result = prime;
return true;
}
result = null;
return false;
}
int? factor;
int testn = 12700000;
int testd = 6269;
if (findNearestPrimeDivisor(testn, testd, out factor))
{
if (factor == null)
{
Console.WriteLine("{0} is an integral divisor of {1}", testd, testn);
}
else
{
Console.WriteLine("{0} is the nearest integral divisor of {1} to {2}", factor, testn, testd);
}
}
else
{
Console.WriteLine("No near prime divisor found.");
} Note: I am not advanced enough in computer science to evaluate how "robust" this may be; this is written "off the top of my head." I welcome any feedback, or correction.
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
Thanks to Ravi and Bill for both of your answers. I was hoping there would be a way to get the answer required without checking each individual number. There are gaps between divisers of millions in some cases. I shall play about with your suggestions and see what the performance is like.
|
|
|
|
|
Just out of interest here is my modified code. It will search in a both positive and negative direction so that it not be biased either way.
private int FindNearestDiviser(int n, int d)
{
int positiveSearch = d;
int negativeSearch = d;
if (n % d != 0)
{
while (n % ++positiveSearch != 0
&& n % --negativeSearch != 0) ;
if (n % positiveSearch == 0)
{
d = positiveSearch;
}
else if (n % negativeSearch == 0)
{
d = negativeSearch;
}
}
return d;
}
|
|
|
|
|
I like this approach !
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
hello every one m stuck in to creating application whose abstract work is to copy some file from host machine to network machins sheard folder,
i m doing something like this in c#
string lscmd = "robocopy "+ lsCurentWorkingDirectory+ " \\\\CPU219\\Test$ " + lsFileName;
ProcessStartInfo ProcessInfo;
ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + lcmd);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = False;
process = Precess.Start(ProcessInfo);
process.waitforExit();
when m runing this code through windows services its get stuck at process.WaitforExit(), and when m runing this by normal console applicatin application it works well,
plz help me
|
|
|
|
|
its most likely a permissions issue (ie the service is running under an account that doesn't have permission to the share) - have a look here and see if this points you in the correct direction http://serverfault.com/questions/177139/windows-service-cant-access-network-share[^]
[edit] one thing you could do, is try using account credentials (Domain, UserName and PassWord) in ProcessInfo - use your account for the moment, but make sure you blank them out after you've tested it (just so no-one sees your credentials) - if it works, that gives you options [/edit]
|
|
|
|
|
Download video on youtube of what documentation do I need ? if there are good examples raid
|
|
|
|