|
Member 11470100 wrote: My intention here, is to swap the images Ah.. alright, I guess I could've seen that
You have a small mistake in that first "block" (and maybe also in others, please check):
Image p1 = pic1.Image;
string tag1 = pic1.Tag.ToString();
pic1.Tag = pic8.Tag;
pic8.Tag = tag1;
pic1.Tag = pic8.Tag;
pic1.Image = pic8.Image;
pic8.Image = p1;
The marked line is too many: You set pic1.Tag = pic8.Tag and pic8.Tag has been set to tag1 before, so both pic1.Tag and pic8.Tag are set to tag1 .
Suggestions: pic1.Tag is a string anyway, right? Then just either cast it to a string (to satisfy the compiler), like so:
string tag1 = (string)pic1.Tag;
..or declare tag1 as object. A String is an Object, so doing this doesn't actually change anything but clears up the code:
object tag1 = pic1.Tag;
For swapping you could use a generic method[^], which also clears up the code and explains automatically what your intention is:
public static class MyUtility
{
public static void Swap<T>(ref T left, ref T right)
{
T temp;
temp = left;
left = right;
right = temp;
}
}
Then the whole code from above would look like this:
MyUtility.Swap(ref pic1.Image, ref pic8.Image);
MyUtility.Swap(ref pic1.Tag, ref pic8.Tag);
Member 11470100 wrote: will it be possible to schedule a skype setting so i can share screens and we could go through We prefer to keep it in the forums here - if needed you could upload images to e.g. imgur.com and put the link into your message.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I have a table with 3 columns. Container # , Container Size and Pickup Location.
I am looping through each of the rows and append all the data to a string variable.
However, I also need to store the Pick up location(input by user, and will be same for all containers in a request) to be stored in a variable. How do I go about it?
var pickLoc = document.getElementById('_pickLoc');
for (i=1; i<=lastRow; i++)
{
var dataStr;
var localvar;
var aRow = document.getElementById('txtRow' + i);
if (aRow.value.length <= 0)
{
alert('Row ' + i + ': Container number is empty');
document.getElementById('txtRow' + i).style.backgroundColor = "#ffff99";
document.getElementById('txtRow' + i).focus();
return;
}
else {
document.getElementById('txtRow' + i).style.backgroundColor = "";
dataStr = "<tr><td height=5></td></tr><tr><td><FONT face='Verdana' size='1'>";
dataStr += document.getElementById('txtRow' + i).value;
dataStr += "</Font></td><td><FONT face='Verdana' size='1'>";
}
var e = document.getElementById('_cntrSize' + i);
if (e.options[e.selectedIndex].value == "")
{
alert('Row ' + i + ': Container Size is empty');
e.style.backgroundColor = "#ffff99";
e.focus();
return;
}
else {
e.style.backgroundColor = "";
dataStr += e.options[e.selectedIndex].value;
dataStr += "</Font></td><td><FONT face='Verdana' size='1'>";
}
var LocRow = document.getElementById('txtLocRow' + i);
if (LocRow.value.length <= 0) {
alert('Row ' + i + ': Pick up location is empty');
document.getElementById('txtLocRow' + i).style.backgroundColor = "#ffff99";
document.getElementById('txtLocRow' + i).focus();
return;
}
else {document.getElementById('txtLocRow' + i).style.backgroundColor = "";
dataStr += document.getElementById('txtLocRow' + i).value;
dataStr += "</Font></td><td><FONT face='Verdana' size='1'>";
localvar = document.getElementById('txtLocRow' + i).value;
}
pickLoc.Value = localvar;
ttlStr += dataStr;
}
|
|
|
|
|
What has this got to do with C#?
There's a specific forum[^] for JavaScript questions.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry about that. Posted in the right forum.Thanks for informing.
|
|
|
|
|
I have 3 classes overriding a function of base abstract class A. The child classes are 1, 2 & 3. Child classes override function "public abstract void hello(var1, var2)".
Following is what I want to implement:
abstract class A
{
public abstract void hello(var1, var2);
public abstract void hello(var1, var2, var3);
}
** Currently the above code throws error and wants me to implement the new inherited abstract function in class 1 & 2.
|
|
|
|
|
No, an abstract method in class A must be implemented by all (non-abstract) derived classes.
If the new method is only available in class 3, then add it to class 3. You can't add it to class A, because it's not valid for every instance of a class derived from class A.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
You implementation force Class 1 and 2 to implement "hello(var1, var2,var3)" just because you want to have a extra method for Class 3. This is not a good design to follow.
You should follow Open to extend and close to modification methodology.
you might create an extension of class A and implement it for Class 3. Please refer the approach below:
abstract class A
{
public abstract void hello(var1, var2);
}
abstract class A1 : A
{
public abstract void hello(var1, var2, var3);
}
Implement Class A for Class 1 and Class 2
Implement Class A1 for Class 3
Maddy
|
|
|
|
|
I'm not fully convinced about the quality of this idea, yet decided to give it a try.
Use Case:
I got an abstract class Factory , which then is derived by other classes - Nothing new so far. What I want to have is a single instance of each and every class deriving from Factory . Why? No particular reason, just wondering whether it can be don the way I imagine:
public abstract class Factory
{
private readonly object _instanceLock = new object();
private Factory _instance = null;
internal Factory GetInstance(Type t)
{
if (_instance != null) return _instance;
if(t != typeof(Factory)) throw new InvalidOperationException("Factory can't created an instance not derived from " + typeof(Factory).FullName);
lock (_instanceLock)
{
if (_instance != null) return _instance;
Thread.MemoryBarrier();
var assembly = Assembly.GetAssembly(t);
_instance = (Factory)assembly.CreateInstance(t.FullName);
}
return _instance;
}
protected Factory() { }
}
|
|
|
|
|
Marco Bertschi wrote: Why? No particular reason I'm missing the definition of the object that is being created, but I'm also missing the concept - a factory for a single class?
You are building a generic car-factory, to produce cars that do not come from an assembly-line?
What does it add, what advantages do you gain, compared to simply writing a static-class and using that?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: I'm missing the definition of the object that is being created
A Factory (Stupid naming on my side, probably)
Eddy Vluggen wrote: but I'm also missing the concept - a factory for a single class?
YNOES. As mentioned, the term factory isn't greatly chosen. The idea behind it was to manage documents which are very specific tied to the main application. Some customers prefer databases, some file system store.
My idea however was to have this Big Mama Factory class over two other classes, one managing storage of database stored files the other one managing file system files (God, this terminology sucks).
Do not ask me why I went for singleton first, I then realized that it doesn't add anything an interface couldn't do - But at this point I already wrote it, and now I want to know whether my glitch in the matrix *could* have any *potential* use cases in the real world.
Eddy Vluggen wrote: What does it add, what advantages do you gain, compared to simply writing a static-class and using that?
I shortened the example a bit - From the expectations an interface would fit a lot better.
|
|
|
|
|
Marco Bertschi wrote: Some customers prefer databases, some file system store. Go for a strategy pattern
Marco Bertschi wrote: Do not ask me why I went for singleton first, I then realized that it doesn't
add anything an interface couldn't do That's what got me confused; why singletons? The terminology hints that something is wrong; a factory returns an object it creates (from a class), where in the singleton there is only one instance of the object.
Marco Bertschi wrote: I then realized that it doesn't add anything an interface couldn't do Have the factory return an object, and drop it in an interface; could work in a similar way as we now use the database-classes; you can program against the interface, and have a class instantiate whatever concrete class that you want and pass it along. Similar to that IDbConnection that you can open, you can create a SqlConnection, or a concrete MySqlConnection or a SQLiteConnection.
You could do similarly for your store; the factory should decide which object should be created, and the rest of the application only uses the interface. Create one implementation for the database, one for the filesystem.
It also does not mean that you only want "one" of those objects; you want to be able to instantiate them multiple times, as you would with a database-connection. Yes, there's only one server, but I can talk to it from multiple connections
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Marco Bertschi wrote: What I want to have is a single instance of each and every class deriving from Factory .
The code you've posted won't do that.
Firstly, if you pass anything other than typeof(Factory) to your GetInstance method, you'll get an InvalidOperationException - typeof(DerivedFactory) != typeof(Factory) .
Secondly, if you pass typeof(Factory) to your GetInstance method, you'll get a MissingMethodException - you can't create an instance of an abstract class.
Thirdly, even if you fix the previous errors, you would only ever be able to have a single instance of one derived class in a single AppDomain. The static field is specific to the Factory class; you don't get a different copy for each derived class.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I agree with the others. There are a lot of problems with trying to do this.
The biggest I have is WHY? What advantage is there to creating a Factory for a class that can only ever have a single instance?
|
|
|
|
|
Hi,
Is it possible to use extension methods in C# using .NET 2 ?
I'm using Visual Studio 2013.
Thanks
|
|
|
|
|
No.
Extension methods were introduced as part of V3.0 - if you want to use them, you must target .NET 3.0 or higher.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
v3.5, shirley? They were added with LINQ.
And, as Sascha said, if you're using the right version of the compiler, you can still use extension methods even if you're targeting v2.
There's even a library[^] which lets you use LINQ in v2, so long as you're using the right compiler.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I didn't know that!
And any day when I learn something new is...well...another day really.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
Yes. To make it work, you have to place this somewhere in your project:
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
ok im trying to make a script placer witch will move loads of files at once and rename them depending what name is in the text box.
the only issue i have it im not sure on how to do this i know its a pain i know the basics of c# made a few programs just dont know how to connect a text box and button to move and rename multiple files all at once if anyone knows how to do this or could help me out a little with example code would be amazing i dont want anyone to create this for me just need a little bit of a understanding in this
thank you all for your time
thanks in advance elfenliedtopfan5
|
|
|
|
|
Many of the class methods in the documentation come complete with example code. For instance, https://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx[^]
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
|
|
|
|
|
can you have me? source code open, save as, and help menu..
example we work on notepad and then save with format (txt) and then open on our program (this program read the txt) then have result after that save as txt again..
in help menu, how to display new form (about) etc.. i dont understand.. help me to finished this project
|
|
|
|
|
I'm afraid that you don't seem to understand the purpose of this site. If you have a need of software, take a look at our articles. If you're lucky, you'll find examples there that give you the help and information you need. If you cannot find a suitable article, then you need to provide us with a detailed explanation of what problems your code is facing. Show us the relevant code sections and explain clearly what errors you are seeing.
What we don't do is write your code for you. That's your responsibility I'm afraid.
|
|
|
|