|
thanks,
internally it will spawn a thread to do my work,
this will definately fasten up things,
but if i can get that single connection for sending mails it will be great
SmtpConnection class is there but its not exposed otherwise i could have achived behaviour seamlessly.
------------------------------
Its not the fall that kills you; it's the
sudden stop at the end.
|
|
|
|
|
hello programmers!
im creating an application to hold my dvd collection (lame, but i have to start somewhere!)
and im having problems adding a DVD object to an ArrayList.
basically...i have a "DVD" object which is coded as follows:-
using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Soap;
using System.Windows.Forms;
namespace DVDDatabase
{
[Serializable]
public class DVD
{
//DVD Properties
public string strTitle;
public int intBoxLocation;
public int intBoxNumber;
public DateTime dtDateAdded;
public int intYear;
public string strGenre;
public string strDirector;
public bool boolWatched;
}
[Serializable]
public class Collection
{
public ArrayList arrDVDCollection;
}
}
(note this is in a seperate .cs file)
so, what i want to do is create an instance of "Collection" at run time right? so, my main method is as follows...
static void Main()
{
//Starts The Application
//Load Preliminary Objects
Collection DVDCollection = new Collection(); <<--HERE IT IS!
//Load GUI
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainMenu());
}
ok, so now, on an "Add DVD" button that i have on a SEPERATE form (called AddDVD.cs) i need a command to add the current DVD object to the array list...here we go again!
private void btnAddDVD_Click(object sender, EventArgs e)
{
//create new instance of dvd object
DVD newDVD = new DVD();
//set properties
//set Title
newDVD.strTitle = txtTitle.Text;
//add Dateadded code here
//Set Year
try
{
newDVD.intYear = int.Parse(numYear.Text);
}
catch (Exception)
{
MessageBox.Show("Please Input A Number For Year");
}
//set Director
newDVD.strDirector = txtDirector.Text;
//add Gennre Code Here
//set BoxNo
try
{
newDVD.intBoxNumber = int.Parse(txtBoxNo.Text);
}
catch (Exception)
{
MessageBox.Show("Please Input A Number For Box Number");
}
//set BoxLocation
try
{
newDVD.intBoxLocation = int.Parse(txtBoxLocation.Text);
}
catch (Exception)
{
MessageBox.Show("Please Input A Number For Box Location");
}
//Set Watched Bool
newDVD.boolWatched = chkWatched.Checked;
//add to array list
DVDCollection.arrDVDCollection.Add(newDVD); <<-HERE IT IS!
//Clear form
}
yeah i know i havent coded everything, but im getting there!
anyway, when i compile i get the following email message:-
"the name DVD Collection does not exist within the current context"
i think this is because the original ArrayList definition is not being referenced on the above form (or something like that) but i am unsure how to go about doing that.
if somebody can understand any of that mess i have just written out and offer some help, i would be very thankful
Kris
|
|
|
|
|
At first glance, you need to initialize the instance of arrDVDCollection in the Collection constructor.
|
|
|
|
|
Yep, I couldn't find any code that does instanciate the arraylist object.
Change
[Serializable]
public class Collection
{
public ArrayList arrDVDCollection;
}
}
to
[Serializable]
public class Collection
{
public ArrayList arrDVDCollection = new ArrayList();
}
}
You're done
- - - --[ i love it when a plan comes together ]-- - - -
|
|
|
|
|
Actually, part from the other answers, DVDCollection is created as a variable in the Main() method so it isn't declared in your btnAddDVD_Click method, so just make it a field of AddDVD class.
Offtopic: I would suggest reading some books about object oriented programming, declaring all your fields as public isn't the way you should be programming
|
|
|
|
|
Hi Friends,
I want know to create shared assembly, i know how to create strong name but i will not able to invoke shared assembly. Any one helps me to come out this suitation.
Gopal M Hatekar
|
|
|
|
|
Have you added the assembly to the GAC (Global Assembly Cache) ??
- - - --[ i love it when a plan comes together ]-- - - -
|
|
|
|
|
I have added assembly to GAC but i am not able to invoke that assembly in application
|
|
|
|
|
And you DO have a reference to the assembly??
- - - --[ i love it when a plan comes together ]-- - - -
|
|
|
|
|
when i am not able to add a reference is it any other to invoke shared assembly.
Gopal Hatekar
|
|
|
|
|
Hi
i want to hide my code in such a way that it can not be seen even using ildasm.exe
can anyone suggest me how can i do that?
regards
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
|
Like the post from edboe, obfuscate the code. There are plently of good tools out there to do this
Here is a turn up from my google[^] search.
|
|
|
|
|
Hi,
i am creating a form to display the actions done to file in a directory.
For the add, delete and rename actions a write line in a textbox.
The directory is accessible through a windows share (on my local machine) and now i am trying to get the username of some external user who is also modifying files on my shared directory.
How can this be done? i now only get the username of the logged in user (being myself ...)
|
|
|
|
|
Hi ,
i want to make a utility using c# similar to replace function in the notepad. i have a file in which i want to replace the all the instances of a string with another string.
Help me in doing that .........
thanks and regards
sankalp verma
Sankalp Verma
|
|
|
|
|
Open the file and read the contains of the file to a string.
Then use, for example:
string myText = myText.Replace("apple", "mango");
|
|
|
|
|
But i have to save the contents to the file also.........
how do i save them into the file?
Sankalp Verma
|
|
|
|
|
Use StreamWriter. Read MSDN.
|
|
|
|
|
Hi there,
I have the following problem:
I want to add a variable 'myServerInfo' to an arraylist.
This variable is of the datatyp 'ServerInfo' (public class).
I can add this variable without any problems to the arraylist with
the command:
<br />
myServerArrayList.Add(myServerInfo);<br />
But how can I have access to this through the arraylist?
If I type in the following commandline, Intellisense will not
provide me the necessary information:
<br />
Console.WriteLine(myServerArrayList[0].???<br />
I thought I can type in:
<br />
Console.WriteLine(myServerArrayList[0].strServerName);<br />
Console.WriteLine(myServerArrayList[0].strServerIP);<br />
Console.WriteLine(myServerArrayList[0].strServerNetMask);<br />
My complete code for this example is like:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Collections;<br />
<br />
namespace ConsoleApplication1<br />
{<br />
public class ServerInfo<br />
{<br />
public string strServerName;<br />
public string strServerIP;<br />
public string strServerNetMask;<br />
}<br />
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
ArrayList myServerArrayList = new ArrayList();<br />
ServerInfo myServerInfo = new ServerInfo();<br />
myServerInfo.strServerName = "Server 1";<br />
myServerInfo.strServerIP = "192.168.0.1";<br />
myServerInfo.strServerNetMask = "255.255.255.0";<br />
myServerArrayList.Add(myServerInfo);<br />
Console.WriteLine(myServerArrayList[0].???<br />
}<br />
}<br />
}
If anybody gives me a hint,
I can go on with my project.
Thanks in advance
Erik
|
|
|
|
|
What you get from the ArrayList is a reference to the type Object. You have to cast the reference to the actual data type:
(ServerInfo)(myServerArrayList[0])
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I tried
MessageBox.Show((ServerInfo)(myServerArrayList[0]).strServerName);
but it won't work
'Object has no definition for strServerName'
Erik
|
|
|
|
|
In (ServerInfo)(myServerArrayList[0]).strServerName ...
It won't if the cast is applied after having attempted to retrieve the strServerName in (myServerArrayList[0]) which is recognized as an object type instance.
|
|
|
|
|
Add parentheses so that you access the property of the ServerInfo object, not the Object object.
MessageBox.Show(((ServerInfo)(myServerArrayList[0])).strServerName);
---
b { font-weight: normal; }
|
|
|
|
|
Since anything derived from object can be stored in your ArrayList, Intellisense does not "know" what kind of object is stored in the 0th position. You need to cast it before: ((ServerInfo)myServerArrayList[0]). ... or use something more appropriate than ArrayList. Try List<ServerInfo>
|
|
|
|
|
You have to cast it since it returns an object:
(myServerArrayList[0] as myServerInfo).strServerName
|
|
|
|