|
This is a compiler error yeah?
post the code for the whole class, I'm sure you're missing something. maybe like a semi colon. You haven't got one at the end of your commented out line, so maybe you've got an extra on on a line below, so when you change the comments the semi colons are correct.
All the lines you've provided compile fine for me (I just had to add the semi colon to get the commented out line to compile).
Simon
|
|
|
|
|
Are you sure you write your code in the right place?
|
|
|
|
|
|
Nice one. we all make simple mistakes from time to time.
Simon
|
|
|
|
|
Hi friends,
My requirement is to maintain a collection of products based upon categories and i have to
retrieve that.For ex:i can retrieve different book names which are under the category Book..Say i
can retrieve all mobile company names which are under the category Mobile.I was told to use
collections here... What i suppose to do is to use list of arraylists...The list contains the
category(Book) and the arraylist under that list contains the products(All book names under book)
[List]------>[Array lists under the list]
[Book]----->[TamilBook][EnglisgBook][MathsBook]
[Mobiles]--->[Nokia][SonyEricson][Motorola]
I need code in C#.Net...Any known friends help me...
Thanks in advance....sherin
|
|
|
|
|
angelsherin wrote: What i suppose to do is to use list of arraylists
Sounds like a dumb idea. I'd use a dictionary/hashtable, then you can look up the collections directly. I'd never, ever use an arraylist or any other collection that's not strongly typed via generics.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
There's lots of ways of doing this. Firstly Arraylists are kind of considered old now. Instead you should use generics.
Personally, I would define a Product class, then have all products inherit from the product class, so Book would inherit from product and mobile would inherit from product etc.
Then have a List<Product> myList = new List<Product>() which can store all the products.
To get all products of certain types, you could use a Linq query.
(I'd never tried this with linq before, so I knocked up a quick test)
class Program
{
static void Main(string[] args)
{
List<product> myList = new List<product>();
myList.Add(new Book("Beginners C#", "Some author"));
myList.Add(new Book("Advanced C#", "Anon author"));
myList.Add(new Book("Expert gardening", "Mr Carrot"));
myList.Add(new Book("Step by step guide to plane building", "Mr S. Pitfire"));
myList.Add(new Mobile("Nokia N70", true, 3));
myList.Add(new Mobile("Sony W810", false,2));
var query = from b in myList
where b is Book
select b as Book;
foreach (Book book in query)
{
Console.WriteLine(book.ProductDescription + " by " + book.Author);
}
Console.ReadLine();
}
}
public class Product
{
private String _productDescription;
public Product(String productDescription)
{
_productDescription = productDescription;
}
public String ProductDescription
{
get
{
return _productDescription;
}
set
{
_productDescription = value;
}
}
}
public class Book : Product
{
private String _author;
public Book(String productDescription, String author)
: base(productDescription)
{
_author = author;
}
public String Author
{
get
{
return _author;
}
set
{
_author = value;
}
}
}
public class Mobile : Product
{
private bool _is3G;
private int _cameraMegaPixels;
public Mobile(String productDescription, bool is3G, int cameraMegaPixels)
: base(productDescription)
{
_is3G = is3G;
_cameraMegaPixels = cameraMegaPixels;
}
public int CameraMegaPixels
{
get
{
return _cameraMegaPixels;
}
set
{
_cameraMegaPixels = value;
}
}
public bool Is3G
{
get
{
return _is3G;
}
set
{
_is3G = value;
}
}
}
</product></product>
Simon
|
|
|
|
|
Hi,
Using VS 2008, I have developed a windows service which monitors files activities on the network.
At present I have hard coded a few settings such as Folder to monitor, email address to send emails when files are changed, etc...
What is the best way to have these settings so that a user can change these settings when necessary?
I was thinking of adding these settings inside an app.config file as xml in the windows service project and let the service to read these settings from the app.config. Not sure if this is possible and if it is a good idea.
If I follow this route then how can a user change these settings?
What do you think?
Thanks
|
|
|
|
|
arkiboys wrote: settings inside an app.config file
This will work fine, but to edit the settings the user would have to manually edit the XML. With app.config files, the initial defaults are stored in the app.config in the program directory, but any user changes are stored in the documents & settings\username\application data folder, so finding the right file to change would be difficult for the user. Additionally, the data can only really be accessed by the app that owns it because it's folder path is formed with some kind of hash of the apps assembly name, so it would be difficult to write an app to provide a nice user interface.
What would be better would be to use isolated storage. You could store an XML settings file in isolated storage. You could then write a separate application that would access this XML file and provide a nice interface for the user to change the settings with.
Simon
|
|
|
|
|
The service will sit on only one server on the network.
So may be it is ok to have the settings in the app.config file?
Thanks
|
|
|
|
|
arkiboys wrote: The service will sit on only one server on the network.
So may be it is ok to have the settings in the app.config file?
Well, it's basically up to you.
I'd use a settings class and set the scope to "application" this means they are read only settings, you just set them manually during deployment. These will be stored in the app.config file.
Simon
|
|
|
|
|
Ok, I have done this now.
I now would like to change these settings from a winform application.
Is there a way to do this please?
Thanks
|
|
|
|
|
Do you have any experience using the webbrowser control in .NET?
I am having problems trying to handle click events in .NET
on HTML elements added programmatincally.
I am creating the HTML doc at runtime from data in a database
and I need to creat links that I can handle events for in .NET
so I can do things on the click event.
But I can create a element using Document.CreateElement("a")
and assign click event handler like this
anchor = _WebBrowser.Document.CreateElement("a");
anchor.InnerText = "Add Comment";
anchor.Id = "lnkAddComment";
anchor.SetAttribute("href", "#");
anchor.Click += new HtmlElementEventHandler(lnkAddComment_Click);
But in the event handler when you interrogate the sender object it gives
a generic "HtmlElement" as the source control and not the actual name
of the link that the click was initiated by.
Any ideas how I can handle events for programmatically created links??
rotsey
|
|
|
|
|
can i convert Timespan datatype to int.
if yes please show me example
regards
|
|
|
|
|
It depends on how you want the timespan to be represented as an integer. Many of its properties return an int already.
Dave
|
|
|
|
|
what do u want to do with the int?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
i think u just use Ticks property of time that timespan but it returns 64 bits integer (long).
TimeSpan ts = new TimeSpan(DateTime.Now.Ticks);
long ticks = ts.Ticks;
dhaim
program is hobby that make some money as side effect
|
|
|
|
|
I have an aspx page to serve images. Basically it reads image from file using FileStream, creates a Bitmap using Image.FromStream and writes the bitmap to the output using bitmap.Save(Response.OutputStream). The image files are small in size but this page will get a lot of hits so I'm anxious about performance hit. Is there a way to read an image using streams (or any other better way) to the client without using memory like Response.TransmitMemory()?
|
|
|
|
|
No.
Everything you do requires memory. The CPU performs operations on stored memory, (usually in registers), not from disk. Without some kind of hardware gizmo you cannot do things without moving the data through memory.
Just manage your memory carefully. Ensure that once the image has been sent to the client, it is removed from local memory.
Simon
|
|
|
|
|
Why are you decoding the file into a Bitmap object? Do you change the image in any way before sending it as response?
Otherwise just use Response.WriteFile .
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi all
I'm having a problem with delegate. In my project I have 2 forms, form1 and form2. From form1 I have a button there just for opening form2. And from form2 I have a text box there to enter an Int value. After getting a value from the text box I want to send it back to form1 and appear in a text box on form1.
I do this with a delegate but I don't know if my way is the way you use to solve this problem or not.
Here is my code:
Form1
<code>
public delegate void TestDelegate(int i);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frmOpen = new Form2();
frmOpen.ShowDialog();
}
public void GetValueA(int i)
{
textBox1.Text = i.ToString();
}
}
</code>
Form2
<code>
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int b;
b = Convert.ToInt32(textBox1.Text);
Form1 frm1=new Form1();
TestDelegate td = new TestDelegate(frm1.GetValueA);
td(b);
Close();
}
}
</code>
|
|
|
|
|
The way I do this is to create a public event and delegate in Form2. After I create the new instance of Form2 but before showing it, I subscribe to the event.
Dave
|
|
|
|
|
Hi.
Try to create this in Form2:
public int GetNumericValue()
{
this.ShowDialog();
int iOut = 0;
int.TryParse(textBox1.Text, out iOut);
return iOut;
}
and change the button_click event to
private void button1_Click(object sender, EventArgs e)
{
Form2 frmOpen = new Form2();
textBox1.Text = frmOpen.GetNumericValue().ToString();
}
This is similar to the good old InputBox in VB.
Kjetil
|
|
|
|
|
This is my Login Page URL
http://localhost:3271/NocSystem/LoginPage.aspx
This is my Admin(Home)Page URL
http://localhost:3271/NocSystem/AdminPage.aspx
If i copy & paste the home pages URL with another Browser it is loading.I want to avoid that.Because if one of user got that URL he can easily access to my web base system through my web server.I'm developing this system to run @ my office's web server.
If one of user copy and paste that URL i wanna redirect to my Login Page.How can i do that...?
Its urgent..!!!
CheeN
|
|
|
|
|
sacr83 wrote: Its urgent..!!!
No, not really, I have all the time in the world. It's only urgent for you, and frankly no-one cares about that.
Now, if you weren't so bloody impatient and double posting, you would have realized, you are posting this in the incorrect forum. This should go to ASP.NET.
|
|
|
|