|
You only use | and & when you want both conditionals to be evaluated. Here is a somewhat crass example:
if(amanda.AttemptKiss() & sarah.AttempKiss())
Console.WriteLine("I'm back at university");
Even if you fail to kiss Amanda, you still want to try to kiss Sarah.
|
|
|
|
|
hehe, example of kisses
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
You should also check
if ( amanda.AttemptKiss ( sarah ) )
I would also consider having individual variables for containing individual references as too limiting and would instead use a Queue<Girls> .
|
|
|
|
|
To be pedantic.
<br />
Queue<girl> girls = new Queue<girl>();<br />
PopulateFromBar(girls);<br />
foreach(Girl g in girls){<br />
try {<br />
Drink d = bar.GetDrink();<br />
this.AttemptFlirt(g);<br />
g.Imbibe(d);<br />
this.AttemptKiss(g);<br />
this.CopAFeel(g);<br />
this.InviteHome(g);<br />
this.AddCompanion(g);<br />
this.Successes++;<br />
break;<br />
} catch(SlapException e) {<br />
this.AvoidList.Add(e.Girl);<br />
this.Drink(bar.GetDrink());<br />
} catch (RejectionException e) {<br />
this.Drink(bar.GetDrink());<br />
}<br />
}<br />
<br />
this.Travel(this.Home);<br />
</girl></girl>
For me, Successes is without a doubt a signed short. Can you get smaller than a short? I suppose we want a ridiculously large number that will never be reached in the future (*cough*640k*cough*), so that will do
|
|
|
|
|
John Oxley wrote: Can you get smaller than a short?
SByte
But don't let them know you have only a short.
if ( g.HasFriend )
{
this.WingMan.Add ( g.Friend ) ;
}
And try not to use break in a foreach , in fact why foreach a queue ?
|
|
|
|
|
hi all...
i am wroking with a c#.net application and i need to send fax ( pdf file )thru application.
for that i used faxcomlib.dll and its working fine, if i send .txt or .doc or .tiff.
But if i try to send a pdf file as fax it is giving error as shown below:
The data is invalid. (Exception from HRESULT: 0x8007000D)
I am using w2k3 server and vs2005 and i am also having a PDF reader . The document that should be sent is outside folder of application. is it required to give any permissions and all?
plz its really urgent .
Thnaks in advance
KIRAN
|
|
|
|
|
I am quite new to C# and I think this is a really easy fix...I just can't find it. I am creating a GUI calculator for my class and am slowly learning the language MS Visual Studio 2008. [I started on Java]
My main question is:
I created some buttons, a menu, and text fields in the design part of the program, but when I try to run the program to test it, all these widgets are disabled. I checked the properties value and “Enabled = true”. Is it because I have not bound a handler to them yet?
I am also not sure if I need to put something else in the method handler. Here is my = method. Do I need to use the sender/e parameters elsewhere or is that done by the language/IDE?
private void buttonEnter_Click(object sender, EventArgs e)<br />
{<br />
di = Double.Parse(inputImaginary.Text);<br />
c = Double.Parse(inputReal.Text);<br />
<br />
a = printReal; bi = printImaginary;<br />
<br />
switch (operatorSymbol)<br />
{<br />
case '+': addition(c, di); break;<br />
case '-': subtraction(c, di); break;<br />
case '*': multiplication(c, di); break;<br />
case '/': division(c, di); break;<br />
case '=': printReal = c; printImaginary = di; break;<br />
default: break;<br />
}<br />
<br />
outputImaginary.Text = printImaginary.ToString();<br />
outputReal.Text = printReal.ToString();<br />
}
Thank you very much for your time and help. I think next time I am just going to hand code the GUI.
|
|
|
|
|
First, Visual Studio is an IDE, not a language.
Did you double click on the button in design mode to create the event handler, or did you just type in the code? Search your solution to see if you've set the event handler - it should look like this:
this.buttonEnter.Click += new System.EventHandler(this.buttonEnter_Click);
You can set breakpoints to see if the handler is being executed.
Cheers,
Vikram.
"real dictators don't loose[sic] elections." - Diego Moita.
|
|
|
|
|
I checked and the aforementioned code is included and I did double click all the event items to create the handlers.
I also put a breakpoint at this spot and stepped through the program. It is being called. When the programs appears though everything is grayed out.
---------------------
EDIT
I went ahead and re-created the project. It works normally now. I have no idea why the other one is acting the way it is.
Thanks again.
modified on Thursday, February 21, 2008 1:11 PM
|
|
|
|
|
I've just found a quite nifty way to make typed generic factory methods using lambdas.
The concept makes it possible to get intellisense for the args passed to the factory.
Normally this is not possible because generic factory methods normally just take "params object[] args".
So for those geeky enough to care:
http://rogeralsing.com/2008/02/21/typed-factories-in-c3-managed-new/[^]
|
|
|
|
|
I'm simply tying to Access Fido.Age, Fido is a object created in Form1 from the class Dog.
Please look trough the project savefile, it's in C# 08.
http://www.stigern.net/WindowsFormsApplication1.zip
I would be VERY happy if someone helped me! Really stuck at this one
|
|
|
|
|
Sigh. Seeings that you probably aren't going to do the proper thing and actually implement something like the MVC pattern, you might want to look at this[^] article.
|
|
|
|
|
Hi,
I'm trying to implement some functionality found in a SIGGRAPH paper by Karl Sims called Artificial Evolution for Computer Graphics. In this paper he uses LISP functions to create what is known as Genetic Art.
I am keeping the same general structure as his techniques (using LISP-like nested list expressions), but I have chosen to run it with C#.
In his paper he references several functions: bitwise and, or, xor -- which operate on floating point numbers. However, the C# compiler will not let me do bitwise expressions with floating points. Is there any way I can get around this?
Thanks.
|
|
|
|
|
Specify the number of decimal places you want. Multiple your numbers by 10^x. Then, cast to int, do your operations, and then divide again to get your result.
Or write a fixed point class that wraps this stuff for you.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
Hi Christian,
Thank you for your response.
Just to make sure I understood what you were saying - something like this?:
double BitwiseAnd(double l, double r)
{
int scale = (int)Math.Pow(10, 8);
int left = (int)(scale * l);
int right = (int)(scale * r);
double result = (left & right);
return result / scale;
}
|
|
|
|
|
i would say yes, but cast to long to preserve precision
Silence is the voice of complicity.
Strange women lying in ponds distributing swords is no basis for a system of government. -- monty python
Might I suggest that the universe was always the size of the cosmos. It is just that at one point the cosmos was the size of a marble. -- Colin Angus Mackay
|
|
|
|
|
he might want to cast to long to preserve precision.
Silence is the voice of complicity.
Strange women lying in ponds distributing swords is no basis for a system of government. -- monty python
Might I suggest that the universe was always the size of the cosmos. It is just that at one point the cosmos was the size of a marble. -- Colin Angus Mackay
|
|
|
|
|
Or use Decimal? Decimal allows access to the individual bytes.
|
|
|
|
|
Hi Christian,
Did you mean multiply by 2^x? Testing with 10 ^ x did not give me the correct results.
|
|
|
|
|
No, I meant, for example, if you have 1.234567 and you want 4 significant figures, you turn it into 12345 ( so, four figures after the decimal ), then do your operation, and then divide by 10000 again to get your floating point number. If Decimal works better, go for that, b/c this seems expensive to me.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
One possibility would be to use the BitConverter class, whether this gives you the results your after I'm not sure, it seemed to work for the values 0 and 1.
<code>
static double BitwiseAnd(double x, double y)
{
return BitConverter.Int64BitsToDouble(BitConverter.DoubleToInt64Bits(x) & BitConverter.DoubleToInt64Bits(y));
}
</code>
|
|
|
|
|
Hi,
I expect you will want good performance too, so all those Math.Pow operations and stuff,
or the Converter class which needs array objects, are not really appropriate.
There is a rather cheap way of creating "unions" (as in C) by defining a struct with
explicit offsets, so variables of different types can made to overlap. It takes some Marshal
attributes to get it right.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
i'm using this library : http://www.codeproject.com/KB/directx/directshownet.aspx[^]
and i have a problem to use ISampleGrabber with a AVI file reader (IBasicVideo2).
See my code :
<br />
Type comType = null;<br />
object comObj = null;<br />
<br />
comType = Type.GetTypeFromCLSID(Clsid.SampleGrabber);<br />
if (comType == null)<br />
throw new NotImplementedException(@"DirectShow SampleGrabber not installed/registered!");<br />
comObj = Activator.CreateInstance(comType);<br />
<br />
sb = (ISampleGrabber)comObj;<br />
<br />
baseGrabFlt = (IBaseFilter)sb;<br />
<br />
<br />
AMMediaType media;<br />
media = new AMMediaType();<br />
media.majorType = MediaType.Video;<br />
media.subType = MediaSubType.RGB24;<br />
media.formatType = FormatType.VideoInfo;<br />
hr = sb.SetMediaType(media);<br />
if (hr < 0)<br />
Marshal.ThrowExceptionForHR(hr);<br />
<br />
hr = graphBuilder.AddFilter(baseGrabFlt, "Ds.NET Video Capture Device");<br />
if (hr < 0)<br />
Marshal.ThrowExceptionForHR(hr);<br />
<br />
<br />
<br />
<br />
<br />
<br />
Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero;<br />
media = null;<br />
<br />
sb.SetOneShot(false);<br />
<br />
sb.SetCallback(this, 1);<br />
The callback is never call.
Someone can help me ?
|
|
|
|
|
There's a forum under that article for a reason.
Have you tried it ?
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
I dont know how to fix my error. Could someone help me out.
I use C# expression.
namespace ConsoleApplication1
{
private void rand_seed()
{
int seed = (int)(time(0));
RandomNumbers.Seed(seed);
}
private double get_RandomNum(double x, double y)
{
return x + (y - x) * RandomNumbers.NextNumber() * (1.0 / RAND_MAX);
}
private static int Main()
{
rand_seed();
double x_cor = 0;
double y_cor = 0;
double x_sum = 0;
double y_sum = 0;
double x_y_total = 0;
int num_darts = 0;
int num_hits = 0;
int num_misses = 0;
double pi_approx = 0;
Console.Write(" Throw the dart: ");
num_darts = SimulateCin.ReadToWhiteSpace(true);
Console.Write("\n");
if (num_darts != 0)
{
for (int i = 0; i < num_darts; i++) // Start of for loop inside the while loop
{
x_cor =get_RandomNum(1.0, -1.0);
y_cor =get_RandomNum(-1.0, 1.0);
x_sum = (x_cor * x_cor);
y_sum = (y_cor * y_cor);
x_y_total = Math.Sqrt(x_sum + y_sum);
if (x_y_total <= 1)
{
num_hits++;
}
else
{
num_misses++;
}
}
} // end of if loop
pi_approx = (1.0 * num_hits /num_misses);
Console.Write(" The value is ");
Console.Write(pi_approx);
Console.Write("\n");
return 0;
}
}
|
|
|
|