|
Oh sorry, I misread the brackets.
Well, because the last term is always false, the compiler detects that the whole clause never can become true. The or-clause becomes always true, bug then the and-clause will become false anyway.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Greeeg,
please look to following code I have implemented:
Please try this code:
string a = "MR";
string b = "MRS";
string c = "BAKER";
string d = "Meyers";
if
(
((string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MR")) &&
(string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MRS"))) ||
((string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MRS")) &&
(string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MR"))) &&
(string.Equals(c.TrimEnd().TrimStart().ToString().ToUpper(),
d.TrimEnd().TrimStart().ToString().ToUpper()))
)
{
MessageBox.Show("ERROR");
}
The result of the first 4 lines of the if-expression becomes TRUE -- o.k.
but the comparison of c.Trim and d.Trim is FALSE so the whole expression (due to the &&) has to become false but the code is running into the MessageBox bracket
why
thank you for your help
Frank
|
|
|
|
|
this is strange indeed, looks like the && operator is evaluated BEFORE the || operator - I thought they are handled equally.
If you want the || clause to be evaluated before, better put brackets around the first two expressions.
This is a test I made:
string a = "MR";
string b = "MRS";
string c = "BAKER";
string d = "Meyers";
bool b1,b2,b3,b4,b5;
b1 = string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MR");
b2 = string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MRS");
b3 = string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MRS");
b4 = string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MR");
b5 = string.Equals(c.TrimEnd().TrimStart().ToString().ToUpper(), d.TrimEnd().TrimStart().ToString().ToUpper());
bool b6, b7;
b6 = (((b1 && b2) || (b3 && b4)) && b5);
b7 = ((b1 && b2) || ((b3 && b4) && b5));
if(b6)
{
MessageBox.Show("ERROR");
}
regards
/edit:
This supports my theory:
Operator precedence and associativity
modified 12-Sep-18 21:01pm.
|
|
|
|
|
They have different precendence.
A lot of things have in C#...
The PROgrammer Niklas Ulvinge aka IDK
|
|
|
|
|
Hi,
I need to find the relation between the windows user(username with which he logged ) ,his session id and the process that were started by him.All these informations are available in the task manager but how do i get them through the code.
Does c# directly have any procedures to find this or if there are any other API's.Please let me know.
Thanks
|
|
|
|
|
System.Environment.UserName returns the Windows username of who started the thread that is calling that static property.
For the rest try to see MSDN for System.Diagnostics.Process and its members.
You can also access system infos using System.Diagnostics.PerformanceCounter that allows you to read information about cpu, ram, hdd usage, running processes, threads, modules and so on... That is a little complicated to use...
|
|
|
|
|
can ne1 plz tell me hw m goin to do this..
i hav a function in which i execute the datareader
ie--dataReader = SqlHelper.ExecuteReader(SQLConn,CommandType.StoredProcedure,"USP_GET_DATA" );
i declare getobj as array of objects..
after it gets all the data from the database in getobj ,
i want to fill the datagrid with the data...m not using dataset at all...m getting the values of each row in getobj
in the form_load
private void frmIATA_CODES_Load(object sender, System.EventArgs e)
{
NFDataObjects.IATACodeRequest [] getobj;
getobj=getIATA();
//here i want to write code to fill the datagrid with getobj which is array of objects
dataGrid1.//how to populate the datagrid???
}
ne help is appreciated....
|
|
|
|
|
Hi there friends,
I am working on a program that its language is not english(so mine!).
every time user wants to change the language he must press ALT+SHIFT
and this is annoying.How can I change language programatically?
Thank You!
|
|
|
|
|
Question: I would like to know if is there a method to send a mouse click to an application, more precisely to the apllication that stays behind my window.
Essentially I need to build a click-through window.
thanks to all.
|
|
|
|
|
Hello
I made a small software in C#. I want to add help feature in it. I dont know how to to do it Can any body give me an idea or help me in this regrad.
Regards
Asmyan
|
|
|
|
|
Install the "HTML Help Workshop" utility which comes with the Visual Studio. See the detailed help in this utility for creating HTML help (.chm file) for your program. Basic steps are as under:
1. Create a new Help project using the File-New command.
2. Add HTML files for the topics to be included.
3. Add / create Index and Contents file which will be used for the Contents / Index tabs in your help system.
4. Add graphics files etc. inside your html topic files.
5. Change properties of the help project file as per requirements.
6. Compile the help project to give you the .chm file.
Details on these individual topics can be seen in the HTML Help Workshop utility's help file which gives step-by-step details.
|
|
|
|
|
Excuse me, but where is located the HTML Help Workshop on the Visual Studio CDs? I tried with the standard installer but there is not. I searched on the CDs but I found only the HTML Help compiler, not the editor.
|
|
|
|
|
Have you guys ever realised that when you have a component class that has a timer, and when your Thread calling the method finishes off, the Timer events still gets fired.. Why is this so.. Look at the following code as an illustration.
public class WithTimer : System.ComponentModel.Component
{
private System.Timers.Timer timer1;
public WithTimer(){}
public void StartTimer()
{
int i=0;
while(true)
{
if(i==0)
timer1.Start();
i++;
}
}
}
public class MainApp
{
public static void Main()
{
WithTimer m_Timer = new WithTimer();
Thread _Thread1 = new Thread{new ThreadStart(m_Timer.StartTimer)};
_Thread1.background = true;
_Thread1.Start();
_Thread1.Abort();
}
}
Now as you can see in the code, after _Thread1.Abort(), i realise that m_timer events still gets called, even after the Thread has exited gracefully.
This ONLY happens with the Timer events. Anyone know why this is happening ?
Any solutions to this ?
Stanley
|
|
|
|
|
That's how Timers are supposed to behave, aren't they? They keep firing off events at regular intervals of time, until you call Stop.
By the way, why are you starting timers in a thread? Starting a timer is not going to take much time, you can do it in the main thread itself.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Reason being, I want to create a listener per thread.
Stanley
|
|
|
|
|
jbx1628 wrote:
Anyone know why this is happening ?
The Timer class creates a thread to run itself in. This obviously stays alive, but logically you would think if the thread that created it was aborted, it should abort any 'child' threads too. This doesnt seem to be the case though.
Now the solution should be:
override Dispose(bool disposing)
{
timer1.Dispose();
base.Dispose(disposing);
}
This should be called when the finalizer is called for the WithTimer either by calling Dispose() or letting it be GC'd.
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
Yeah, this is my curiosity as well. I taught any if the parent thread gets created, all it's child will get NUKED. Thanks for pointing this out...
Stanley
|
|
|
|
|
How can i capture the net send packts using C#.NET or in any other language. kindly help me.
Thnaks in advance.
Shahzad
|
|
|
|
|
you have to sniff TCP packets, but I don't know how to do this in C#. try searching on CodeProject: I think there is something useful
|
|
|
|
|
Hi,
I have made windows service program
In On start code i am calling exe file through process.start
inside on_start()function
Process.Start(@"c:\a.exe"); here i do not want to write complete path
I want to write only a.exe and path should be taken from my other project which i made another installation program for this project.
How can i retrive the path of a.exe so that my windows service automatcally retrive the path of location of a.exe
Client can install set up program of a.exe in any drive.
In that case how my windows service will retrive the complete path of a.exe
Pls suggest in this matter
This is very urgent
THanks and Regards
sanjeev
Everything is possible
|
|
|
|
|
Just write the path where a.exe is being installed to into the registry: Add a new registry key to your setup for a.exe and set its value to [TARGETDIR] .
Regards,
mav
|
|
|
|
|
Say i had a main class like..
class MainClass : Form
and i had another class
class Control
can I add a function to an event handler through the Control class to the mainclass? if not is there a way around this? any solutions will be appreciated thx for the help.
IM PROUD TO BE A GMAIL;
|
|
|
|
|
If I am reading you correctly, then the answer is yes.
((MainClass) this.ParentForm).MyEvent += new ...
|
|
|
|
|
Hi everybody.
Can somebody direct me to a correct algorithm to solve the sort problem of the following array of data:
ServerWeb.*
ServerWebSomething1
ServerWebSomething2
ServerWeb3
ApplicationServer1
App.*
ApplicationServer2
should be sorted as this:
ApplicationServer1
ApplicationServer2
App.*
ServerWebSomething1
ServerWebSomething2
ServerWeb3
ServerWeb.*
The point is that the data is first sorted alphabetically, and then withing the similar types of data I need to get the data with more specific to the top and those less specific to the bottom.
For instance, as ServerWeb.* covers all servers that starts with the "ServerWeb" it is the least distinctive, while ServerWebSomething1 is the most distinctive in that subgroup.
This just puzzles me, I would appreciate any algorithm in any language if C# example is not available.
Thanks.
|
|
|
|
|
What you need to do is to define a way to compare two of the values. If you just do that, you can then use any sorting algorithm. You can even make a class that implements ICompareable and use the SortedList class to sort them.
What information does the names contain? How do you separate the different parts of information? Why is, for an example, "ServerWebSomething1" more distinctive than "ServerWeb3"?
---
b { font-weight: normal; }
|
|
|
|