|
Hello. I am using a hastable to store and retrieve class objects. Now I can successfully get an object based on some key but the problem is: I can not return it from within the function. Here is what I am trying
public ClassName FindObject(int nKey)
{
ClassName obj = new ClassName();
obj = (ClassName)HashTable[nKey];
return obj;
}
Now the line (ClassName)HashTable[nKey] is successful to find the required object but obj is still equal to null. Thanks for any input on this.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Hashtable hashtable;
private void button1_Click(object sender, EventArgs e)
{
Test t1 = new Test();
t1.variable = 1;
Test t2 = new Test();
t2.variable = 2;
hashtable = new Hashtable();
hashtable.Add(1, t1);
hashtable.Add(2, t2);
Test tc1 = GetClass(1);
tc1.ShowVar();
Test tc2 = GetClass(2);
tc2.ShowVar();
}
public Test GetClass(object id)
{
return (Test)hashtable[id];
}
}
public class Test
{
public int variable;
public void ShowVar()
{
Console.WriteLine(variable);
}
}
|
|
|
|
|
Can you post the code using the function FndObject?
The code you posted above doesnt seem to have any problems.
|
|
|
|
|
Why are you creating a new ClassName instance when the variable obj id immediately overwritten in then next statement?
The next thing you don't understand is that trying to retreive a an object via a key from a Hashtablehttp://msdn.microsoft.com/en-us/library/system.collections.hashtable.item(v=vs.80).aspx[^] will return null when there is nothing stored under that key:
MSDN wrote: The value associated with the specified key. If the specified key is not found, attempting to get it returns a null reference (Nothing in Visual Basic), and attempting to set it creates a new element using the specified key.
So what happens here is that whatever you passed into FindObject as a key has no instance of type ClassName associated with it.
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Furthermore, the element at nKey may not be of type ClassName or a derived class - then the cast to ClassName will change it to null.
|
|
|
|
|
Hi can anybody plesae tell me is there any opensource BPM for .net rather than www.netbpm.org......
Thanks in advance
modified 5-Oct-12 2:36am.
|
|
|
|
|
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I am developing C# application.desktop application.
I am using Visual Studio 2010 & SQL server 2008
I am new to C#.
If I want to print a bill by taking a total of entry filled text boxes(i.e. printout of selected items only or non empty text boxes)then how will I do it?
I 'Bill' form I have taken 20 fileds for exa. nursing charges,anesthesia charges,likewise..
Different treatment requires different types of charges so,i will do entry only in selected fields among these 20 fields.
Bill printout should contain the fields which I have entered.
How will I do this?
Can anybody please help me?
Thank in advance.
|
|
|
|
|
S Akshay wrote: How will I do this?
Can anybody please help me?
With picking a report-generator? How about starting on MSDN[^]?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
How to trigger C# events using jquery
|
|
|
|
|
You might find this[^] a useful starting point.
|
|
|
|
|
I hope it may help you..
JQuery:
$(document).ready(function () {
$('#button1').click(function (event) {
$('#button2').click();
event.preventDefault();
return false;
});
});
HTML:
<asp:Button runat="server" ID="btn1" onclick="btn1_Click" Text="Button One" ClientIDMode="Static" />
<asp:Button runat="server" ID="btn2" onclick="btn2_Click" Text="Button Two" ClientIDMode="Static" />
<asp:Label runat="server" ID="lbl2"></asp:Label>
code behind for button2 click event:
protected void btn2_Click(object sender, EventArgs e)
{
var test2 = "test2";
lbl2.Text = "btn2_Click";
}
Paly
|
|
|
|
|
When I try to write to a comment tag field and save the file, I get either expected result, wrong result or an error. Does anyone have suggestions or tips? The intent is to add text to the metadata of jpg images so that I can search images later. Here's the code sofar:
private void buttonOpenFile_Click(object sender, EventArgs e)
{
using(OpenFileDialog d = new OpenFileDialog())
{
d.InitialDirectory = @"D:\";
d.Filter = "All jpeg files|*.jpg;*.jpeg";
d.ShowDialog();
_File = TagLib.File.Create(d.FileName,"image/jpeg", TagLib.ReadStyle.None);
}
textBox1.Text = _File.Tag.Comment;
}
private void buttonSaveFile_Click(object sender, EventArgs e)
{
_File.Tag.Comment = textBox1.Text;
_File.Save();
}
|
|
|
|
|
|
I already studied all i could find...no solution sofar!
|
|
|
|
|
Please help me how i read equation from word and display on asp .net page.
|
|
|
|
|
Please read this[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hello. I dont know deeply about this but; I know that private inhertience most likely means composition. Now I am using private inheritence in my small c++ project like this
BOOL ChildClass::Function()
{
return BaseClass::Function();
}
Now there is no private inhertence in C#. I can use composition here but how will I call BaseClass functions in ChildClass like above. How do I achieve this in C#? Thanks
This world is going to explode due to international politics, SOON.
|
|
|
|
|
protected is the keyword you are looking for.
MSDN (via Google) says: The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances.
Protected sits in a sense between public and private.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thanks for your reply. If ClassB is derived from ClassA using protected, and then ClassC is derived from ClassB using protected THEN; functions of ClassA will be available in ClassC as well. However, this is not the case when we implement same scenario using private inheritence. Am I wrong somewhere?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
My background is more C++ than C#, so I'll suggest you look beyond me. Google threw up a lot of good stuff on "C# composition vs inheritance", including Composition VS Inheritance[^] right here on CP.
It also seems that you may need to drag in interfaces, depending on your exact needs.
Happy hunting,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
As you have discovered, there is no real concept of private inheritance in C#. You can't hide the public properties and methods of a base class. The only real way that you could achieve this would be to have a member variable in your class, instead of using that type as a base class, and you'd just work with that.
|
|
|
|
|
AmbiguousName wrote: Now there is no private inhertence in C#.
Probably because there is so little point in using it.
I wouldn't be surprised if most uses really arise from a misuse of inheritence when someone thinks that inheritence is nothing more than a code simplification tool.
|
|
|
|
|
In a C# 2008 application, I have a foreach loop that is listed below:
for each (PkgID in PkgIDs)
{
Process eProcess = new Process();
String Process_Arguments = null;
eProcess.StartInfo.UseShellExecute = false;
eProcess.StartInfo.FileName = strConsoleAppLocation;
Process_Arguments = filedirectorypath + " 7654" + PkgID;
eProcess.StartInfo.Arguments = Process_Arguments;
eProcess.Start();
eProcess.WaitForExit(1800);
eProcess = null;
Process_Arguments = null;
}
As you can see from the code I listed above I have the following questions:
1. For each iteration of the for loop I create a new process object called eProcess and then I set
eProcess = null; near the end of the loop.
Thus can you tell me if this is code or not and why? If you have better code that I could use would you tell me what you recommend by pointing me to some code I can use as a reference?
2. You can see that I also have the following line of code,
eProcess.WaitForExit(1800);
I have this line since the process that is being called does not seem to complete its processing before the control is returned to this program.
Thus can you tell me the following:
a. Is the number of milliseconds that I specify a good amount? Can you tell me why or why not?
b. Since the code is returned to this calling program before the entire eProcess finished, can you tell me if this is a good way to wait for the eprocess to finish? I would think there is a better way to what for eProcess to finish. If so, is there a way to tell when the eProcess
is really finished executing?
|
|
|
|
|
foreach (PkgID in PkgIDs)
{
Process eProcess = new Process();
String Process_Arguments = null;
eProcess.StartInfo.UseShellExecute = false;
eProcess.StartInfo.FileName = strConsoleAppLocation;
Process_Arguments = filedirectorypath + " 7654" + PkgID;
eProcess.StartInfo.Arguments = Process_Arguments;
eProcess.Start();
eProcess.WaitForExit();
System.Threading.Thread.Sleep (1800);
eProcess = null;
Process_Arguments = null;
}
|
|
|
|