|
Thanks Guyz,
I have tried it as this but the problem is i have to put all the methods in a another class progam such as PrimeNumClass.cs and i have to call that in the main program to display the output.
here is my code:
<br />
namespace PrimeNumber<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
int n = 2;<br />
int totalPrimeNumbers = 0;<br />
int x;<br />
double sumOfPrimes = 0;<br />
<br />
while (n <= 100)<br />
{<br />
bool isPrime = true;<br />
<br />
for (x = 2; x < n; x++)<br />
{<br />
if ((n % x) == 0)<br />
{<br />
isPrime = false;<br />
break;<br />
}<br />
}<br />
<br />
if (isPrime == true)<br />
{<br />
Console.WriteLine(n + " is a prime Number.");<br />
<br />
sumOfPrimes = sumOfPrimes + n;<br />
totalPrimeNumbers++;<br />
}<br />
n++;<br />
}<br />
<br />
<br />
}<br />
}<br />
}<br />
Here everything is in Main Program itself. But i want it all in a seperate class Nmaed PrimeNumClass.cs and i have to call that class in the main Class to display the output.
please help me. itz very urgnet.
regards,
Chitra
|
|
|
|
|
chitra4sat wrote: Here everything is in Main Program itself. But i want it all in a seperate class Nmaed PrimeNumClass.cs and i have to call that class in the main Class to display the output.
Creating a new class is easy. Just right click on your project and click on Add then Class from the pop menu. Fill in the text box with the name of your of your class, in this case, PrimeNumClass.
The IDE will create a source file for you that looks like this:
using System;
using System.Collections.Generic;
using System.Text;
namespace PrimeNumber
{
class PrimeNumClass
{
}
}
Now, once you get to this point, you need to add a method to the class that contains your prime number algorithm. In this case, it would probably be best to make the method static. Also, make sure that it has public access so that it can be called from your Main function.
I'm going to leave it here and let you take over. If you have any problems, feel free to ask.
|
|
|
|
|
Hi Thanks,
I have created it as you said the PrimeNumClass as you have mentioned .
but what are all the things have to be inside that class and let me know it by code.
becoz i have the output in the main program and all the funcctions are carried out there. but i have been asked that in the main program there should not be anything but we have to create the object and w ehave to call that method to display the output of the prime number.
so please help me what to do ?
|
|
|
|
|
chitra4sat wrote: but what are all the things have to be inside that class and let me know it by code.
becoz i have the output in the main program and all the funcctions are carried out there. but i have been asked that in the main program there should not be anything but we have to create the object and w ehave to call that method to display the output of the prime number.
You need to add a method to your PrimeNumClass. For example, in your Program class, you have a method named Main. When you run your console application, the application invokes your Main method.
So add a method to your PrimeNumClass. You need to give your method a name, return type, and specify its access. In addition you need to decide if your method takes any arguments. For example, below is a class with no methods:
namespace ClassDemo
{
public class MyClass
{
}
}
Now, let's add a method to it that doesn't return anything and takes no arguments:
namespace ClassDemo
{
public class MyClass
{
public void SayHello()
{
Console.WriteLine("Hello!");
}
}
}
The class now has a method called SayHello. If I want to use this class, I can create an instance of it and invoke the SayHello method:
MyClass mc = new MyClass();
mc.SayHello();
Based on what I've shown you here, add a method to your PrimeNumClass. Then put the code you have in your Main method into this method.
|
|
|
|
|
I am trying create an Automation Add-in for Excel using .NET as per http://blogs.msdn.com/eric_carter/archive/2004/12/01/273127.aspx[^], and http://www.codeproject.com/dotnet/excelnetauto.asp[^] using SharpDevelop V2.00. Having chosen to 'Register for Com Interop" in the project properties, a build produces the error "Cannot Register Assembly. Exception has been thrown by the target of an invocation. (MSB3217) Microsoft.Common.Targets."
As a complete newbie to C# and knowing nothing about .NET and COM, searching through forums and google on the error message, I still have no clues as to how to get rid of the error.
Can anyone point me in the right direction?
|
|
|
|
|
I'd like to change the way the value displayed in the grid.
So I create a class which derived from UITypeEditor and I have overriden the GetPaintValueSupported and PaintValue methods. Unfortunately there is a small rectangle display in the grid. Is there a way to remove this rectangle? So that I can draw whatever I want.
Thanks in advance....
|
|
|
|
|
Unfortunately this is impossible to get rid of this rectangle. It is painted internally AFTER your have painted inside the rectangle.
|
|
|
|
|
How is the function for block website that have been enter in text box and click add button it will appear in listbox. All this is in one form only.And another button for remove the web site have been add in listbox. The web site have been block will block by browser and this web site cant be acess. Please help me.Thanks A lot.
Below are the coding for the web site bloking form:
//List box
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
//TextBox
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
//Add button
private void Add_Click(object sender, EventArgs e)
{
}
//Remove
private void Remove_Click(object sender, EventArgs e)
{
}
Tq...
|
|
|
|
|
I writing an windows app in C# that receives data via serial port.
I have a thread dedicated to reading from the serial port and when
it has a full packet, it makes a call to the main form.
CallBackUpdate callBack = new CallBackUpdate(updateState);<br />
Invoke(callBack, new object[] { newPacket });<br />
So it passes the newPacket to a method called updateState.
Lets say this happens: (Although I don't think it will)
1.Receive one packet and is sent to main form for processing.
2.Receive another packet and send it to main form before packet from 1 is done processing.
Question/Concern
Will the main form process the first packet completely before it processes the second?
or
Do I have to add some blocking to the serial thread so that it doesn't send a packet for
processing when another is being processed.
|
|
|
|
|
dino2094 wrote: Invoke(callBack, new object[] { newPacket });
Careful here. This will block until the Form invokes the delegate and it completes. Your serial port thread won't be able to do anything else. Perhaps try BeginInvoke instead.
dino2094 wrote: Will the main form process the first packet completely before it processes the second?
Yes.
dino2094 wrote: Do I have to add some blocking to the serial thread so that it doesn't send a packet for
processing when another is being processed.
Well, you get that for free by using Invoke rather than BeginInvoke. But I'm betting you'd probably want to use BeginInvoke instead.
|
|
|
|
|
Program type: preferably windows service
Program Description
Part 1: polls sql table for recs with certain criteria (needs to check every minute or so)
Part 2: If part 1 finds recs that match, then part 2 needs to retrieve those records and do some work to them. (convert the records data into a xml document)
Part 3: The newly created xml document needs posted to a clients website (which gives a response of an error code or confirmation #)
Part 4: The original sql record needs updated with the confirmation and a flag signifying the task is done.
I am having problems figuring out how this should be done.. for instance if part 1 is checking every minute by using a timer if parts 2 - 4 haven't completed after part 1 has notified them the first time it might try to notify about the same records again
How would you keep everything organized
|
|
|
|
|
Mischievious wrote: I am having problems figuring out how this should be done.. for instance if part 1 is checking every minute by using a timer if parts 2 - 4 haven't completed after part 1 has notified them the first time it might try to notify about the same records again
Stop the timer after a match has been found. Restart it after completing part 4.
|
|
|
|
|
Thanks Leslie,
I guess that would be the logical thing to do. For some reason I was thinking that I needed to keep the polling part running while I was processing the records.
Thank you again for your help.
|
|
|
|
|
I am working on a project to encode videos by WMEncoder and having a problem.
If a video has no sound at all, then audio source shouldnt be created and added into group:
IWMEncSource SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
SrcAud.SetInput("C:\\Inputfile.mpg", "", "");
But how to figure out if a video has sound or not?
The other question is how to cut thumbnail from a video by WMEncoder or WMFormat? I didnt see any samples.
Thanks!
|
|
|
|
|
I need to store configuration data in a single file and allow several projects to use this one file. For example:
<projects>
<project_one>
<authorname>Some name</authorname>
<projectname>some name</projectname>
<fullpath>D:\My Projects\Projectname1</fullpath>
<date>Date</date>
<param_one>some parameter</param_one>
</project_one>
<project_two>
<authorname>Some name</authorname>
<projectname>some name</projectname>
<fullpath>D:\My Projects\Projectname2</fullpath>
<date>Date</date>
<param_one>some parameter</param_one>
</project_two>
</projects>
I am confused about which class to use XmlTextReader/XmlTextWriter or XmlDocument? I simply need to append new project nodes, delete old ones, and retreive the data when necessary.
Thanks,
Mark
|
|
|
|
|
I think all your requierments can be fullfiled using XmlDocument Class[^]
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
<br />
<span style="color: #0000FF;">public static</span> Bitmap BytesToBmp( <span style="color: #0000FF;">byte</span>[] b, <span style="color: color: #00CC99;">Size</span> imageSize )<br />
{<br />
<div style="padding-left: 5px;"><br />
<span style="color: #009933;">
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: color: #00CC99;">MemoryStream</span> stream = <span style="color: #0000FF;">new</span> <span style="color: color: #00CC99;">MemoryStream</span>( b, <span style="color: #0000FF;">true</span> ); <br />
</div><br />
<div style="padding-left: 5px;"><br />
stream.Write( b, 0, b.Length ); <br />
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: #009933;">
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: color: #00CC99;">Bitmap</span> bmp = <span style="color: #0000FF;">new</span> <span style="color: color: #00CC99;">Bitmap</span>( stream ); <br />
</div><br />
<div style="padding-left: 5px;"><br />
stream.Close(); <br />
</div><br />
<div style="padding-left: 5px;"><br />
bmp = <span style="color: #0000FF;">null</span>; <br />
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: #0000FF;">return new</span> <span style="color: color: #00CC99;">Bitmap</span>( bmp, imageSize ); <br />
</div><br />
}<br />
I'm getting an error: System.ArgumentException: Parameter is not valid.
Then when I use the Stream Object I get:
Cannot create an instance of the abstract class or interface 'System.IO.Stream'.
I'm at a lose on how to create a Bitmap from a Stream if I can not create a Stream.
I was under the impression that a derived class such as: MemoryStream would work.
Any help explaining this would be helpful.
Thanks.
I'm listening but I only speak GEEK.
|
|
|
|
|
I did something like this the other day, using the static Bitmap.FromStream() method. Here's my code - my bitmap was encoded in a string...
<br />
MemoryStream ms = new MemoryStream( Convert.FromBase64String( eImage.InnerText ) );<br />
Bitmap bmp = Bitmap.FromStream( ms ) as Bitmap;<br />
Why do you stream.Write()? Isn't the data already in the MemoryStream from the constructor?
I also don't understand why you set bmp = null, or what the purpose of constructing a new Bitmap on return.
|
|
|
|
|
Nick Hodapp wrote: Why do you stream.Write()?
Basiclly this is the first time I'd used it and based of examples I'd found, I thought I need to perform the write to prepare the stream.
Nick Hodapp wrote: I also don't understand why you set bmp = null
I'll be calling this method hundreds of times with ASP.NET and will need to make sure that Garbage Collector knows I'm done with the variable.
I'm still getting the same error message[^]. I've added a link to a screen shot of the error message. Thanks for your help.
I'm listening but I only speak GEEK.
|
|
|
|
|
Parts of your code are a mess. Also, you don't say where the errors occurred - this is important and I cannot guess where.
Lets examine the code:
MemoryStream stream = new MemoryStream( b, true );
stream.Write( b, 0, b.Length );
I'm not sure about your thought processes here. You create a MemoryStream using the contents of the buffer, b, which contains the data. Then you write the contents of b into the stream. But the stream already contains the contents of b. I suggest that the Write operation is redundant.
Bitmap bmp = new Bitmap( stream );
stream.Close();
This seems reasonable.
bmp = null;
return new Bitmap( bmp, imageSize );
I am curious as to what you think this actually does. I don't mean to be unkind, but I really don't understand your thought process.
The following would seem to be a good way forward:
using(MemoryStream ms = new MemoryStream(b))
{
Bitmap bmp = new Bitmap(ms);
return bmp;
}
|
|
|
|
|
Colin Angus Mackay wrote: Also, you don't say where the errors occurred
Error Message[^]
Understanding the logic behind the MemoryStream basiclly this is the first time I'd used it and based of examples I'd found, I thought I need to perform the write to prepare the stream.
I'm still getting the same error message. I've added a link to a screen shot of the error message. Thanks for your help.
I'm listening but I only speak GEEK.
|
|
|
|
|
Thank you every one for your help.
public static Bitmap BytesToBmp( byte[] b )
{
using ( MemoryStream ms = new MemoryStream(b , true) )
{
Bitmap bmp = Bitmap.FromStream( ms ) as Bitmap;
return bmp;
}
}
Works great. This is was the byte[] that I was sending the method; it was not being recognized by the Bitmap Constructor. I am storing images within an Access 2003 db, (yes, not a good idea), and the way Access had been altering the byte [] so that the Bitmap Constructor couldn't recreate it. I'm not sure n exaclty what Access was doing with the Image but I as inserting a bitmap from file to it. ???
If anyone know the answer to this, please drop me a line. Otherwise, I'm now converting the image and inserting it into the database using a FileStream in and then a FileStream out. If anyone is interested I will post the project when I've completed.
Thanks again!!
I'm listening but I only speak GEEK.
|
|
|
|
|
'Adaptive Resonance Theory'
ART network is a 'Neural network'.
the goal is design an Art with C#,
because Matlab not supprt Art netwok.
in the network is a parameter than named vigilance factor
this factor to care network in front of learned pattern
|
|
|
|
|
Interesting. Do you have a concrete question too or are you simply expecting us to write the whole thing for you?
In case you're looking for some ideas on how to implement neural networks in C#, search the articles. There are some covering the topic.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
hello... i wanted to segment a picture into characters using histograms... i managed to do so but now the code throws exception "image already locked"...
this exception is not thrown all the time but is thrown sometime... i think it is because image although is unlocked (i did unlocking) according to statement but the area might still be captured in ram or so... plz correct me if i am wrong and also show me some way to control the exception as it occurs at times and not all the time....
please provide help
and are there any algos for character segmentation apart from histogram and connected components one... which will work better...
haseeb
|
|
|
|