 |
 |
Index ‹ DotNet ‹ Visual C#.Net
|
- Previous
- 1
- Net Framework >> I can't open .net web application from VS. NET 2003I try to open one .net based web application from VS.Net 2003 in my Windows
2K server, get following error message "Visual Studio .NET has detected that
the specified Web server is not running ASP.NET version 1.1" and also tried
to command line command aspnet_iisreg /i and aspnet_iisreg /r but didn't
work.
Could somebody give me some idea to solve this issue? Thanks a lot!
- 2
- ADO >> Truncate function???Does anybody know if there is a similiar function in MS
Access like the ORACLE "TRUNCATE" function?
eg:
trunc(RSS_TRACKING.COMPLETION_DATE) AS COMPLETION_DATE
result is: 6/29/03
The truncate function basically will aggregate dates
(which I have in my GROUP BY clause) based off of a
common starting point, like every Sunday, for instance.
I tried using ROUND, but it seems only for numbers, not
dates. I also tried using the CONVERT and CAST functions
in addition to the ROUND function, but still couldn't do
the date conversion.
Thanks,
Bill.......
- 3
- Dotnet >> Bind datatable to excel worksheetIt is possible bind a memory AdoNet Datatable to an Excel wooksheet and,
after update of datatable contens (via code), view update in real time on
the woorksheet?
I am starting use Visual studio tool for office to make this task: it is the
correct way?
thank's in advance for help
gianni
- 4
- Microsoft Project >> how to represent a continuous activity in a project plan?hi,
i have been working on a project plan and wanted to add certain activities
in the plan which are of "continuous" nature. For example, "communication",
"status reporting" are activities that are going to span throughout the
project and according to the plan, they'd consume around 15% effort of the
Project Manager throughout the project alongwith other activities.
For this purpose, I could simply add a task in the plan and assign 15%
resource UNITS to each of them. Since these activies are to be started right
from the very first day of the project, i know the start date, but the end
date of these tasks will actually be the LAST day of the project deadline
since these activities are going to last till the last day. Since, this LAST
day will vary depending on the changes i will be making during the project,
it cannot be fixed. I don't want to manually assign the end date myself, but
would like it to "update" automatically as i make changes to rest of the
plan.
I tried adding dependency of the 1st and last task from the WBS with
following type:
1st Task, Start to Start
Last Task, Finish to Finish
By doing so, i was hoping to tell MS project that this task is going to
start with the 1st Task and End with the Last task. But it didn't work.
Maybe this is not the way to do it. Can someone please help me understand
how to do it?
Thanks!
Akhlaq.
- 5
- Microsoft Project >> Graphical indicator for %complete and durationi want to display graphical indicator depending on the %completion
field value.For instance if the %Completion is less that 50% then the
stoplight should alert with RED.But here i have to consider the
duration(%duration).for instance if %completion is 20% when the
%duration is also 20% then its fine.But if duration% is 80% and
%completion is 30% the we should alert about this.what i need is can we
derive a formula and then based on the value we can display the
Stoplight.That is considering both %complete and duration-completed.
any suggesstions
- 6
- Visual C#.Net >> Setup Project Prereq'sI am building a Setup Project in Visual Studio 2008 for a project which only
requires .NET Framework 2.0. When I build the Setup Project and attempt to
utilize the .MSI file created by the Setup Project, the computer complains
that .NET Framework 3.5 is required to run the setup. Can I configure the
Setup Project to be built using .NET Framework 2.0 instead of 3.5? The end
result is that my machines have 2.0 installed and I don't need 3.5 for the
application I am trying to install?
- 7
- Net Framework >> Looking For An Example Of Replacing Only One Occurrence In A StringDoes anyone have an example of replacing only one occurrence of a
substring in a string. I have tried replace, but it replaces all
occurrences of the new string in the string. I only want to replace
the specified occurrence in the string (i.e substring(37, 10) - phone
number) with a new phone number. Am I making any sense here or do I
need to provide more detail ?
- 8
- Visual C#.Net >> Windows Communication FrameworkHi,
I have recently published an article on WCF at CodeProject
http://www.codeproject.com/useritems/edujini_wcf_scart_01.asp
It would be great the experts can provide a feedback on the same. Please
note that this is my first article in the series. I have submitted Part-2 to
the editorial team. Simultaneously, I have also posted it at Eduzine
http://eduzine.edujinionline.com/
DirectLink:
http://eduzine.edujinionline.com/index.php?/archives/22-Exploring-Windows-Communication-Foundation-Part-2.html
Hoping that I met some quality standards... :)
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
- 9
- Microsoft Project >> Default workflow of tomesheets and task updatesHi i'm Prasanth,
I would like to know default workflow of task updates and timesheets of
Projectserver 2007 from perspective of project manager and team member.
When a Project manager assigns a
task to team member he is not able to see the tasks under mytasks but can see
them under mytimesheet.Many small organisations have only one manager who
approves both timesheets and task updates of team members.How can i achieve
this in project server 2007 as in project server 2003.
- 10
- Microsoft Project >> Project Comparison ColumnWhen I do a Project Comparison, I can no longer see the column with
the symbols. The "+" & "-" in green and red no longer appear.
Any idea how I can make this column appear again???
Thanks!
J
- 11
- Dotnet >> how to get compatibilityHi,
I have some pages an ASP.NET application when i run in IE 5.0/6.0 it is
showing all the controls when i run the same application in different
browser
i.e natescape navigator then it is showing error....
I mean to say there is no browser compatibility in my application how do it
set this..It should display in any browser...
Thanx In advance
Yoshitha
- 12
- Dotnet >> Print PDFHow to print a PDF file from .NET ?
If I have a normal PDF file how kan I Print the file to a printer using .NET ?
Best Regards
Kim
- 13
- Visual C#.Net >> Media recording and delivery via C#I want to be able to record media off CD's and onto the C: drive, and then
control display - all via the framework.
Is the Media Player SDK ActiveX control the best for this? Or some other
solution?
Thanks,
John
- 14
- Dotnet >> Capturing login event in Service ApplicationI am writing a Windows Service Application and want to be able to capture when the user is logging into Windows. Is there any way within .NET to do this? Basically, I need the equivalent to the SystemEvents.SessionEnded event.
--
Dan S
- 15
- Winforms >> Window Forms and panelsShould anything even a menu, toolbar or statusbar ever be directly placed on
the main window or should they always be placed on a container such as a
panel?
Bill
|
| Author |
Message |
RakeshB

|
Posted: Thu Feb 10 07:58:22 CST 2005 |
Top |
Visual C#.Net >> if else ...
How can I use in If statement Or?
for example. if (x>10 or y>10)
{
....
}
Hrcko
DotNet171
|
| |
|
| |
 |
Glenn

|
Posted: Thu Feb 10 07:58:22 CST 2005 |
Top |
Visual C#.Net >> if else ...
Do you mean
if ( x > 10 || y > 10 )
{
}
Glenn
"Hrvoje Voda" <EMail@HideDomain.com> wrote in message
news:cufon9$seb$EMail@HideDomain.com...
> How can I use in If statement Or?
>
> for example. if (x>10 or y>10)
> {
> ....
> }
>
> Hrcko
>
>
|
| |
|
| |
 |
Paul

|
Posted: Thu Feb 10 08:16:54 CST 2005 |
Top |
Visual C#.Net >> if else ...
"Hrvoje Voda" <EMail@HideDomain.com> wrote:
> How can I use in If statement Or?
> for example. if (x>10 or y>10)
if (x > 10 || y > 10) // or
if (x > 10 && y > 10) // and
P.
|
| |
|
| |
 |
Jako

|
Posted: Thu Feb 10 10:07:11 CST 2005 |
Top |
Visual C#.Net >> if else ...
"Paul E Collins" <EMail@HideDomain.com> wrote in message
news:cufqcm$hue$EMail@HideDomain.com...
> "Hrvoje Voda" <EMail@HideDomain.com> wrote:
>
>> How can I use in If statement Or?
>> for example. if (x>10 or y>10)
>
> if (x > 10 || y > 10) // or
>
> if (x > 10 && y > 10) // and
>
> P.
>
>
It might be worth mentioning short-circuiting for the conditional statements
above.
if (x > 10 | y > 10) will work fine in this case.
by using || it "short-circuits" the conditional, i.e. it will evaluate x >
10 and only if this is false, y > 10 will be evaluated.
Similarly in if(x > 10 && y > 10), x > 10 will be evaluated and only if tihs
is true, y > 10 will be evaluated.
In the case mentioned it won't make a difference, but be careful when doing
something like:
(1) if (++x > 10 || ++y > 10)
as opposed to
(2) if (++x > 10 | ++y > 10)
In (1) ++y will only be execute if ++x is greater than 10, but in (2) both
++x and ++y will be executed.
I don't to confuse the issue, but I do think it's important to keep this in
mind.
|
| |
|
| |
 |
Hans

|
Posted: Thu Feb 10 10:25:17 CST 2005 |
Top |
Visual C#.Net >> if else ...
Jako Menkveld wrote:
> "Paul E Collins" <EMail@HideDomain.com> wrote in message
> news:cufqcm$hue$EMail@HideDomain.com...
>
>>"Hrvoje Voda" <EMail@HideDomain.com> wrote:
>>
>>
>>>How can I use in If statement Or?
>>>for example. if (x>10 or y>10)
>>
>>if (x > 10 || y > 10) // or
>>
>>if (x > 10 && y > 10) // and
>>
>>P.
>>
>>
>
>
> It might be worth mentioning short-circuiting for the conditional statements
> above.
>
> if (x > 10 | y > 10) will work fine in this case.
>
> by using || it "short-circuits" the conditional, i.e. it will evaluate x >
> 10 and only if this is false, y > 10 will be evaluated.
>
> Similarly in if(x > 10 && y > 10), x > 10 will be evaluated and only if tihs
> is true, y > 10 will be evaluated.
>
> In the case mentioned it won't make a difference, but be careful when doing
> something like:
>
> (1) if (++x > 10 || ++y > 10)
>
> as opposed to
>
> (2) if (++x > 10 | ++y > 10)
>
> In (1) ++y will only be execute if ++x is greater than 10, but in (2) both
> ++x and ++y will be executed.
>
> I don't to confuse the issue, but I do think it's important to keep this in
> mind.
>
>
>
or a different example:
if (myObject == null || myObject.TheProperty == 0) ...
*without* short-circuit it would fail on the second test if "myObject"
was null, *with* short-circuit it is perfectly legal.
--
Hans Kesting
|
| |
|
| |
 |
Marcos

|
Posted: Thu Feb 10 10:56:44 CST 2005 |
Top |
Visual C#.Net >> if else ...
Yes, it is important to keep short-circuiting in mind, but IMHO using a
bitwise operator in a logical operator context is just asking for trouble,
exactly because of side-effects like you get with short circuiting. If
you're performing bit manipulations, use the bitwise operators. If you're
performing conditional tests, use the logical operators.
While it's certainly true that there is an equivalence between a bool value
and a bit, in the sense that you can get by with only one or the other if
you have to, the two exist for a very good reason: they encapsulate
different concepts. Bool exists to represent the abstract concepts "true"
and "false", while bits exist to hold the _numeric_ values 0 and 1. Just
because there is a straightforward mapping from {0,1} to {false,true}
doesn't mean that you should feel free to use the two interchangeably and
still claim that you're writing clean, self-documenting code. You wouldn't
use an int where you want a double, so why would you use a bit where you
want a bool? And along with that philosophy, of course comes the practice
of using the correct operators for the types.
"Jako Menkveld" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> "Paul E Collins" <EMail@HideDomain.com> wrote in message
> news:cufqcm$hue$EMail@HideDomain.com...
>> "Hrvoje Voda" <EMail@HideDomain.com> wrote:
>>
>>> How can I use in If statement Or?
>>> for example. if (x>10 or y>10)
>>
>> if (x > 10 || y > 10) // or
>>
>> if (x > 10 && y > 10) // and
>>
>> P.
>>
>>
>
> It might be worth mentioning short-circuiting for the conditional
> statements above.
>
> if (x > 10 | y > 10) will work fine in this case.
>
> by using || it "short-circuits" the conditional, i.e. it will evaluate x >
> 10 and only if this is false, y > 10 will be evaluated.
>
> Similarly in if(x > 10 && y > 10), x > 10 will be evaluated and only if
> tihs is true, y > 10 will be evaluated.
>
> In the case mentioned it won't make a difference, but be careful when
> doing something like:
>
> (1) if (++x > 10 || ++y > 10)
>
> as opposed to
>
> (2) if (++x > 10 | ++y > 10)
>
> In (1) ++y will only be execute if ++x is greater than 10, but in (2) both
> ++x and ++y will be executed.
>
> I don't to confuse the issue, but I do think it's important to keep this
> in mind.
>
>
>
|
| |
|
| |
 |
Jako

|
Posted: Thu Feb 10 11:08:38 CST 2005 |
Top |
Visual C#.Net >> if else ...
Are you saying it's never a good idea to use | and & for conditional tests?
"Marcos Stefanakopolus" <EMail@HideDomain.com> wrote in message
news:420b9253$EMail@HideDomain.com...
> Yes, it is important to keep short-circuiting in mind, but IMHO using a
> bitwise operator in a logical operator context is just asking for trouble,
> exactly because of side-effects like you get with short circuiting. If
> you're performing bit manipulations, use the bitwise operators. If you're
> performing conditional tests, use the logical operators.
>
> While it's certainly true that there is an equivalence between a bool
> value and a bit, in the sense that you can get by with only one or the
> other if you have to, the two exist for a very good reason: they
> encapsulate different concepts. Bool exists to represent the abstract
> concepts "true" and "false", while bits exist to hold the _numeric_ values
> 0 and 1. Just because there is a straightforward mapping from {0,1} to
> {false,true} doesn't mean that you should feel free to use the two
> interchangeably and still claim that you're writing clean,
> self-documenting code. You wouldn't use an int where you want a double,
> so why would you use a bit where you want a bool? And along with that
> philosophy, of course comes the practice of using the correct operators
> for the types.
>
>
>
> "Jako Menkveld" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> "Paul E Collins" <EMail@HideDomain.com> wrote in message
>> news:cufqcm$hue$EMail@HideDomain.com...
>>> "Hrvoje Voda" <EMail@HideDomain.com> wrote:
>>>
>>>> How can I use in If statement Or?
>>>> for example. if (x>10 or y>10)
>>>
>>> if (x > 10 || y > 10) // or
>>>
>>> if (x > 10 && y > 10) // and
>>>
>>> P.
>>>
>>>
>>
>> It might be worth mentioning short-circuiting for the conditional
>> statements above.
>>
>> if (x > 10 | y > 10) will work fine in this case.
>>
>> by using || it "short-circuits" the conditional, i.e. it will evaluate x
>> > 10 and only if this is false, y > 10 will be evaluated.
>>
>> Similarly in if(x > 10 && y > 10), x > 10 will be evaluated and only if
>> tihs is true, y > 10 will be evaluated.
>>
>> In the case mentioned it won't make a difference, but be careful when
>> doing something like:
>>
>> (1) if (++x > 10 || ++y > 10)
>>
>> as opposed to
>>
>> (2) if (++x > 10 | ++y > 10)
>>
>> In (1) ++y will only be execute if ++x is greater than 10, but in (2)
>> both ++x and ++y will be executed.
>>
>> I don't to confuse the issue, but I do think it's important to keep this
>> in mind.
>>
>>
>>
>
>
|
| |
|
| |
 |
Indie

|
Posted: Thu Feb 10 11:40:44 CST 2005 |
Top |
Visual C#.Net >> if else ...
Paul E Collins wrote:
> "Hrvoje Voda" <EMail@HideDomain.com> wrote:
>
>> How can I use in If statement Or?
>> for example. if (x>10 or y>10)
>
> if (x > 10 || y > 10) // or
>
> if (x > 10 && y > 10) // and
>
> P.
You can do it without the or:
If ( x.ToString().Length() + y.ToString().Length > 2 )
--
Texeme
http://texeme.com
|
| |
|
| |
 |
Bruce

|
Posted: Thu Feb 10 11:57:56 CST 2005 |
Top |
Visual C#.Net >> if else ...
I don't know if Marcos is saying that, but I would.
If you are using | and & for conditional tests, and depending upon that
behaviour, then you are writing code that is difficult to read and
maintain. Who is going to notice, in the middle of a 10,000 line
program, that you wrote
if (++x > 10 | ++y > 10)
instead of
if (++x > 10 || ++y > 10)
?
If I saw that sort of code I'd flip out. I would much rather see this:
x += 1; // or x++; if you insist :)
y += 1;
if (x > 10 || y > 10)
...
You need bitwise operators, | and &, in tests only when there are
side-effects, as you pointed out. IMHO it is far, far better style to
remove side effects from conditions wherever possible, because they're
just one more thing to gloss over and miss when reading code.
Just as one vertical bar instead of two, or one ampersand instead of
two is easy to miss when reading code.
|
| |
|
| |
 |
sadhu

|
Posted: Thu Feb 10 13:43:36 CST 2005 |
Top |
Visual C#.Net >> if else ...
What kind of convoluted logic is this? For avoiding an or, you are
calling two methods and two properties??
Regards
Senthil
|
| |
|
| |
 |
Jako

|
Posted: Thu Feb 10 13:46:48 CST 2005 |
Top |
Visual C#.Net >> if else ...
What you say makes sense, but then again my example wasn't exactly the best.
I definitely agree that with increments it's better to do them outside the
if, I only used that as an easy example.
All I'm saying is that I find it difficult to believe that there is never a
case where you'd rather use the non-short-circuited version.
Why would the language include the functionality if it's completely useless
(not trying to open another can of worms with this question...)?
"Bruce Wood" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
>I don't know if Marcos is saying that, but I would.
>
> If you are using | and & for conditional tests, and depending upon that
> behaviour, then you are writing code that is difficult to read and
> maintain. Who is going to notice, in the middle of a 10,000 line
> program, that you wrote
>
> if (++x > 10 | ++y > 10)
>
> instead of
>
> if (++x > 10 || ++y > 10)
>
> ?
>
> If I saw that sort of code I'd flip out. I would much rather see this:
>
> x += 1; // or x++; if you insist :)
> y += 1;
> if (x > 10 || y > 10)
> ...
>
> You need bitwise operators, | and &, in tests only when there are
> side-effects, as you pointed out. IMHO it is far, far better style to
> remove side effects from conditions wherever possible, because they're
> just one more thing to gloss over and miss when reading code.
>
> Just as one vertical bar instead of two, or one ampersand instead of
> two is easy to miss when reading code.
>
|
| |
|
| |
 |
Bruce

|
Posted: Thu Feb 10 14:12:22 CST 2005 |
Top |
Visual C#.Net >> if else ...
I wouldn't say that the operators are useless. In fact, they're very
useful for doing bit manipulation. It's probably just an accident of
the language that they can also be used for constructing conditional
expressions that don't short-circuit.
The | and & operators are enormously useful for manipulating Enum types
that have the [Flags] attribute. I use them often for that purpose.
I wouldn't use them in a condition, though, because I could always code
the condition in a different way that wouldn't require it, and the
"different way," although it would be much more long-winded, would be
easier to understand.
In fact, I just thought of an example from my own code. In my WinForms
code I have a method that calls a method for each different control on
my form to validate the control's contents and display an error icon if
it's invalid. I want to call every single method, so that any controls
with bad contents will display an error handler icon next to them. So,
I could say:
return ValidateControl1() & ValidateControl2() & ValidateControl3();
However, how many programmers reading my code would notice that there
was only one &, not two, and so every method would always be called.
Instead, I coded this:
bool control1Valid = ValidateControl1();
bool control2Valid = ValidateControl2();
bool control3Valid = ValidateControl3();
return control1Valid && control2Valid && control3Valid;
Yes, it's four times as much code, but now it's very clear that each
method is called in turn, and then the result is being calculated.
|
| |
|
| |
 |
Jako

|
Posted: Thu Feb 10 14:26:12 CST 2005 |
Top |
Visual C#.Net >> if else ...
"Bruce Wood" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
>I wouldn't say that the operators are useless. In fact, they're very
> useful for doing bit manipulation. It's probably just an accident of
> the language that they can also be used for constructing conditional
> expressions that don't short-circuit.
I'm not arguing the fact that they are useful as bit-wise operators, that's
a given, you need those.
>
> The | and & operators are enormously useful for manipulating Enum types
> that have the [Flags] attribute. I use them often for that purpose.
>
Same goes for enum manipulation, this is indeed very handy.
> I wouldn't use them in a condition, though, because I could always code
> the condition in a different way that wouldn't require it, and the
> "different way," although it would be much more long-winded, would be
> easier to understand.
>
> In fact, I just thought of an example from my own code. In my WinForms
> code I have a method that calls a method for each different control on
> my form to validate the control's contents and display an error icon if
> it's invalid. I want to call every single method, so that any controls
> with bad contents will display an error handler icon next to them. So,
> I could say:
>
> return ValidateControl1() & ValidateControl2() & ValidateControl3();
>
> However, how many programmers reading my code would notice that there
> was only one &, not two, and so every method would always be called.
> Instead, I coded this:
This I have a problem with. A programmer who doesn't notice this is
definately not worth his/her salt as a programmer. If you're that concerned
about the quality of the programmers reading your code, why not add a huge
comment block pointing out the fact that you use single &s and not double
&s, this won't waste processor/memory resources of the extra steps and
variables you declare.
I remember a recent discussion about the use of "!" in conditionals, e.g. is
writing if(someBool == false) better coding that if(!someBool)... The
majority of contributors seemed to think the latter, though more difficult
to read, is the better way of coding.
>
> bool control1Valid = ValidateControl1();
> bool control2Valid = ValidateControl2();
> bool control3Valid = ValidateControl3();
> return control1Valid && control2Valid && control3Valid;
>
> Yes, it's four times as much code, but now it's very clear that each
> method is called in turn, and then the result is being calculated.
>
|
| |
|
| |
 |
Bruce

|
Posted: Thu Feb 10 16:11:44 CST 2005 |
Top |
Visual C#.Net >> if else ...
It's not a question of "difficulty of reading" code. That's far too
subjective for me. It's a matter of common practice.
If 99% of the conditions out there use && and || (they do), and you're
reading a long program that somewhere in the middle of it there is a
condition that uses & and |, I can almost guarantee that your brain
will "edit in" the usual operators, and you won't even see it. Even if
you pour over the code four or five times, looking for a bug, you won't
see the slight difference from the usual because your brain will gloss
over it, and you'll be _sure_ that you say && and ||, even though
they're not there.
I say this with confidence because I spent 15 years programming in C, a
language in which people do, in fact, do things like that, and I can
tell you that I and a lot of other programmers missed little details
like this. Not because we weren't good programmers (OK, you can debate
that point :) but because we read a lot of code, and our brains started
getting used to how things were "supposed to look" and thus started to
trick us.
If everyone out there used & and | instead of && and || then I would be
coding
if (myObj != null)
{
if (myObj.Prop == 0)
{
... do something ...
}
}
instead of
if (myObj != null && myObj.Prop == 0)
{
... do something ...
}
because the latter would be unexpected.
All I'm saying is that your average programmer is not going to be
expecting & and | in a condition, and so will not readily pick up on
the special behaviour of that condition. It's better to code the whole
thing out in open code where it will be clearly understood.
As for the "extra processor resources" involved... they're not worth
worrying about. Even if by some chance the compiler doesn't compress it
down into the exact same IL as would be produced by using & or |, a few
extra moves in the world of today's computers is trivial.
|
| |
|
| |
 |
The

|
Posted: Thu Feb 10 16:36:20 CST 2005 |
Top |
Visual C#.Net >> if else ...
sadhu wrote:
> What kind of convoluted logic is this? For avoiding an or, you are
> calling two methods and two properties??
>
> Regards
> Senthil
>
I agree, this would be most puzzling to the average debugger and is
(IMHO) most inefficient and counter intuitive.
JB
At least in my culture.
|
| |
|
| |
 |
Ricola

|
Posted: Thu Feb 10 17:52:54 CST 2005 |
Top |
Visual C#.Net >> if else ...
sadhu wrote:
> What kind of convoluted logic is this? For avoiding an or, you are
> calling two methods and two properties??
>
> Regards
> Senthil
>
Which takes more /work/
evaluating a method and a property on an existing object
or
comparing two objects with a logical action ?
--
Texeme Textcasting Technology
http://texeme.com
Indie Pop Rocks @ SomaFM
http://somafm.com/
|
| |
|
| |
 |
sadhu

|
Posted: Thu Feb 10 23:20:06 CST 2005 |
Top |
Visual C#.Net >> if else ...
Operators are native IL instructions, so they'll be implemented as
efficiently as possible. Your solution involves a call to ToString(),
which happens to be a virtual method, so add in that overhead. You then
call Length, which is a O(n) operation on the length of the string. You
then do the whole thing again, then use the + operator also.
Granted, for tiny strings, it is not much of a deal, but why go through
this much trouble when there is a far *clearer* and effecient solution?
Regards
Senthil
|
| |
|
| |
 |
Bruce

|
Posted: Fri Feb 11 00:22:26 CST 2005 |
Top |
Visual C#.Net >> if else ...
Not that it matters much in context, but in .NET calling .Length is not
an O(n) operation on the string. I believe that .NET stores strings as
length-and-contents, not a string terminated by a sentinel like C and
C++. The .Length operator simply fetches the length from the front of
the string. It doesn't count characters like strlen() does.
|
| |
|
| |
 |
Jako

|
Posted: Fri Feb 11 03:28:18 CST 2005 |
Top |
Visual C#.Net >> if else ...
Fair enough, I can see where you're coming from. So we agree that & and |
as conditional operators are parts of C# that they could've left out.
I'm just happy for having && and || in C#, because in my VB6 days it used to
drive me insane to have to code the way you showed below!
"Bruce Wood" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> It's not a question of "difficulty of reading" code. That's far too
> subjective for me. It's a matter of common practice.
>
> If 99% of the conditions out there use && and || (they do), and you're
> reading a long program that somewhere in the middle of it there is a
> condition that uses & and |, I can almost guarantee that your brain
> will "edit in" the usual operators, and you won't even see it. Even if
> you pour over the code four or five times, looking for a bug, you won't
> see the slight difference from the usual because your brain will gloss
> over it, and you'll be _sure_ that you say && and ||, even though
> they're not there.
>
> I say this with confidence because I spent 15 years programming in C, a
> language in which people do, in fact, do things like that, and I can
> tell you that I and a lot of other programmers missed little details
> like this. Not because we weren't good programmers (OK, you can debate
> that point :) but because we read a lot of code, and our brains started
> getting used to how things were "supposed to look" and thus started to
> trick us.
>
> If everyone out there used & and | instead of && and || then I would be
> coding
>
> if (myObj != null)
> {
> if (myObj.Prop == 0)
> {
> ... do something ...
> }
> }
>
> instead of
>
> if (myObj != null && myObj.Prop == 0)
> {
> ... do something ...
> }
>
> because the latter would be unexpected.
>
> All I'm saying is that your average programmer is not going to be
> expecting & and | in a condition, and so will not readily pick up on
> the special behaviour of that condition. It's better to code the whole
> thing out in open code where it will be clearly understood.
>
> As for the "extra processor resources" involved... they're not worth
> worrying about. Even if by some chance the compiler doesn't compress it
> down into the exact same IL as would be produced by using & or |, a few
> extra moves in the world of today's computers is trivial.
>
|
| |
|
| |
 |
GingerDeafMan

|
Posted: Fri Feb 11 05:39:43 CST 2005 |
Top |
Visual C#.Net >> if else ...
In article <EMail@HideDomain.com>,
EMail@HideDomain.com says...
> Fair enough, I can see where you're coming from. So we agree that & and |
> as conditional operators are parts of C# that they could've left out.
>
> I'm just happy for having && and || in C#, because in my VB6 days it used to
> drive me insane to have to code the way you showed below!
Hi,
I am with Bruce on this one. IMO using | or & as conditional operators
instead of || or && is not recommended. Here is another reason.
Boolean false is generally zero, and true is NOT false. So any non-zero
value equates to be true. This is generally accepted by C programmers
and some have been coding using this fact, e.g., where function return
non zero values denote success (e.g. 0 if a record is not found in a
file, or X where X records have been found).
So consider this (for want of a better example)
if(ValidID && FindRecords())
DisplayRecords();
If ValidID is True and records found then records get displayed. If
Valid is false FindRecords() never gets called. OK so far.
Now consider this
if(ValidID & FindRecords())
DisplayRecords();
If ValidID is true (non zero value). This value depends on the compiler
or the programmer. But what is non-zero? Some say -1 and others say 1.
Whatever. Let's say this is 1 for this example.
If FindRecords() returns 2, denoting 2 records found:
1 & 2 (bitwise calculation) is 0, making this expression false. So
DisplayRecords() never gets called which is wrong, of course.
Admittedly this is not a good example but you get the idea of a possible
dangerous side effect.
Cheers,
Paul.
|
| |
|
| |
 |
Bruce

|
Posted: Fri Feb 11 11:17:22 CST 2005 |
Top |
Visual C#.Net >> if else ...
Paul,
What you say is true in C, but not in C#. C# requires that conditions
be boolean, which is different from int, so you cannot say
int a = 1;
int b = 2;
if (a & b) ...
The compiler will flag the "if" as an error, because the result of the
expression is int, not bool.
|
| |
|
| |
 |
GingerDeafMan

|
Posted: Mon Feb 14 04:09:03 CST 2005 |
Top |
Visual C#.Net >> if else ...
In article <EMail@HideDomain.com>,
EMail@HideDomain.com says...
> Paul,
>
> What you say is true in C, but not in C#. C# requires that conditions
> be boolean, which is different from int, so you cannot say
>
Hi Bruce,
Thanks for this. Did not know this. I am bit of a C# novice really,
having programmed in C and C++ for the best part of last 10 years.
So bitwise operators will still work on bool variables under C#.
Doesn't feel right somehow. Wonder if this is intended by design. I
reckon programmers will start interchanging & and && depending on the
code situation (short circuiting or no). Why not as this is "allowed"?
Time to retune our "C" brains perhaps, and start watching out for & and
&&s.
Cheers,
Paul.
|
| |
|
| |
 |
Bill

|
Posted: Fri Mar 11 11:53:36 CST 2005 |
Top |
Visual C#.Net >> if else ...
"Indie Pop" <EMail@HideDomain.com> wrote in message
news:w0NOd.4978$EMail@HideDomain.com...
> Paul E Collins wrote:
>
>> "Hrvoje Voda" <EMail@HideDomain.com> wrote:
>>
>>> How can I use in If statement Or?
>>> for example. if (x>10 or y>10)
>>
>> if (x > 10 || y > 10) // or
>>
>> if (x > 10 && y > 10) // and
>>
>> P.
>
> You can do it without the or:
>
> If ( x.ToString().Length() + y.ToString().Length > 2 )
>
Not only is this a bad solution, but it is also WRONG
if x = 9 , y = 10
it should be false but your "Solution" says it is true
You might argue that yours gives the "Correct Answer" for:
if (x >9 or y > 9)
but then what about
x = 5, y = -1
Ooops...wrong again.
And god forbid we need to change it to
if (x >15 or y < 7)
The standard solution is a trivial change
Your Broken solution falls apart completely
How about we stick with the "||"?
There is enough unintelligible code out there as it is.
Bill
|
| |
|
| |
 |
| |
 |
Index ‹ DotNet ‹ Visual C#.Net |
- Next
- 1
- Net Framework >> TCPClient - Detectiing loss of remote host connectionBefore I go and make massive changes to a TCP/IP library I made, I was
wondering if the detection of connection loss is possible through the
TCPClient class.
The problem I have is that I make a connection to another application using
a TCPClient in one app and a Listener with Client in the other app. I close
the app with the listener. I then try to send data to the listener app.
TCPClient.Connected returns true after the remote connection is forcefully
closed. I understand that the value of TCPClient.Connect is based on the
success of the previous send/recieve action. When I perform a send operation,
there is no exception thrown. Trying to perform a send operation a second
time throws a socket exception stating the connection was closed at the
remote end.
I was hoping that the exception would be thrown on the first send operation
after the connection was closed. Any way around this or will I have to send
test bytes at the start of each send operation in order to test the integrity
of the TCP connection? Any help would be great thanks :o)
- 2
- Microsoft Project >> merge keysI am curios if there is any way to have multiple merge
keys for MS project. I am working in 2000 and haven't
found a way, but I was wondering if the newer versions had
this feature.
Thanks,
- 3
- Net Framework >> ASP.NET lock upHi. I'm experiening random lockups of my ASP.NET application. I see lots of
these error messages from .NET runtime in the event log:
The description for Event ID ( 0 ) in Source ( .NET Runtime ) cannot be
found. The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event: .NET
Runtime version 1.1.4322.2032- Setup Error: Failed to load resources from
resource file
Please check your Setup.
What does this mean and could it be related to the problem?
Casper
- 4
- Visual C#.Net >> WinForms And XMLI saw the following requirement somewhere:
"....using WinForms and the screens should be described in XML. The XML is
to prescribe both the layout as well as the connectivity to the underlying
model"
Can someone tell me how a Windows Form can be described in XML?
- 5
- Winforms >> Trying to learn more regarding interface based developmentHey guys,
I am looking to learn more about interfaced-based design / component-based
programming. I want to be able to write better code, with easier
maintainability and better code reuse since implementation is separated from
the interface.
Any suggestions on reading material?
Thanks.
- 6
- Visual C#.Net >> PocketIE, Javascript, and C# ActiveX alternative?I posted this in PocketPC newsgroup with no response yet, hopefully
somebody here has an answer.
I have an application that runs locally on PocketPC. The user
interface for this application is HTML with Javascript. The Javascript
on the page instantiates an ActiveX control written in C++ ATL. The
ActiveX does not have a visual interface and its basic functionality is
to access the serial port and do some calculations and return the
result.
I am in process of re-writing the application and was thinking to
create a C# alternative to the C++ ATL ActiveX and maybe even simplify
the installation process by eliminating the need to register the
control.
Is it possible to create a C# control to be instantiated by Javascript
and run by PocketIE locally in a PocketPC? I appreciate it if you can
point me to some articles or sample codes doing this.
- 7
- Visual C#.Net >> Using ResXFileCodeGeneratorEx with VCS Express 2005I'm using Visual C# Express 2005.
I installed ResXFileCodeGeneratorEx from
http://dmytro.kryvko.googlepages.com
and set it as Custom Tool for my resx file.
Trying to run by selecting "Run Custom Tool" causes error
---------------------------
Microsoft Visual C# 2005 Express Edition
---------------------------
Cannot find custom tool 'ResXFileCodeGeneratorEx' on this system.
---------------------------
OK
---------------------------
How to fix ?
Andrus.
- 8
- Visual C#.Net >> Very odd Sort problem when modifying DGV bound data(I posted this in a databinding NG, but it's a VERY low traffic NG so I
thought I would post here as well. I hope no one minds too much, if you do
I'm sorry)
I have a DGV that is bound to a DataTable that is loaded during application
startup. I can sort with all the columns and everything works fine. I have
a method that can be invoked from a context menu that will loop through the
rows of the bound table and modify a specific cell in each row. After
modifying the rows sorting doesn't work for that column anymore.
To give a more familiar example:
Load the Products table from the Northwind DB
Bind to a DGV via a BindingSource object
Test teh sorting by clicking on the DGV columns
add a button and in the click handler, loop through the DataRow collection
and set the ProductID column to the value using an int that increments in
the loop.
Try and sort the ProductID column.
You will get incorrect results, it will sort 20 or so rows, then jump to
another number, then jump again.. it's broken.
I've tried everything I can think of:
calling EndEdit on each row
reseting bindings
etc
Nothing seems to solve it. I'm not one to cry "bug" but this sure seems
like one to me.
Anyone ever experience this? Anyone happen to have a demo application setup
with Northwind they could quickly check this? I've spent over a week now
trying to find the problem and I can't. :(
Any help or input greatly appreciated!
Thanks for reading,
Steve
- 9
- Dotnet >> How to hide a object's inherited properties ?I create a user control object and show its properties through a propertygrid
object in my application. It is sure that there are 100 hundred of properties
inherited from System.Windows.Forms.UserControl and they are all showed on
the propertygrid. Is there a way i can hide all these inherited properties
and show only my user control's properties ?
- 10
- Dotnet >> Legal or Scam??Lately I've been getting lots of spam, selling cheap software. The website was oemsoftwarehouse.com. They supposedly were selling oem software of Borland's Delphi and Microsoft's Visual Studio. They said it was only $60 for Delphi 7 Enterprise, but Borland sells it for over $2,500 USD! I don't know the cost of Visual Studo, but the website was offering it for $130 USD. Generally, if it sounds too good to be true, it isn't. Is there such a thing as an OEM version of Visual studio? If I order this, will I be buying pirated software? Will I be breaking any laws using this software?
Thanks!
Debbie
- 11
- Visual C#.Net >> Using IComparer to Sort a String ArrayHello All,
I stumped and I need some help. I have an unsorted string array that looks
something like:
AA
XXX
Z
and I would like to sort it like:
Z
AA
XXX
or like:
XXX
AA
Z
My research has lead me to using the IComparer interface. What I am having
difficulties with is developing a class that will take an unsorted string
array (as noted above) and return a sorted string array (as noted above)
using the IComparer interface.
Thanks in Advance!
- 12
- Visual C#.Net >> Accessing Resources from an MSG fileWe are attempting to replace one of our legacy services (developed in C++)
with one that is developed as a C# service. The problem that I am
encountering is dealing with the resources that are generated from the MSG
file. These resources are used both by the existing service code (to format
strings for internal use) and by the Event Viewer when entries are written
to the Event Log to be associated with this source.
1. Can I access an existing resource file inside an existing EXE (built from
a VC++ 6 source) from a C# service? I have tried the
CreateFileBasedResoruceManager() call, but either I have the parameters
wrong or this is not possible. The method call actually works, but when I
attempt to retrieve a string, I get an MissingManifestResourceException
error.
2. If I create the resources in a satellite assembly, will the Event Viewer
still be able to use the contents?
-Ken
- 13
- Dotnet >> Windows desktop search API in ASP.NETCan anyone know how to use WDS API in ASP.NET?
I copied the Win App sample to ASP.NET, but recevied the following
error:
Exception Details: System.InvalidCastException: QueryInterface for
interface Microsoft.Windows.DesktopSearch.Query.ISearchDesktop failed.
- 14
- ADO >> Simple Multiple Row Insert QuestionHi everyone,
I have a pretty simple situation and I'm hoping that someone could give
me some advice on the best way to handle it.
I need to insert a whole load of rows into SQL Server 2005 using ado.net.
I use custom business objects to represent the rows. So for example, in
this specific case, I have a big collection of "Booking" objects.
I also have a stored procedure called CreateBooking.
My question is - assuming that I need to import say, 7000 rows in one
go, is simply looping through the Bookings collection and calling the
Stored Procedure for each booking the best way to do things?
Is there some other way to get that much data into the database without
constantly calling the stored procedure 7000 times.
I use the same connection each time, but still, it seems a bit clumsy.
I was wondering if there is a better way.
Many thanks to anyone who can advise...
Simon
PS: I really need to use ADO.net to do this - importing by some other
mechanism isn't going to be possible in this instance
- 15
- Visual C#.Net >> How to make a custom template for my project?Hello there,
I want to ask you guys how to make template for my own project in visual
studio 2005 preferable in c#? Is it very easy to implement ? Need tutorial
for this...
I've seen in the net a few articles about this but i did not understand.
Can anyone tell me how to create this please?
Thanks
Ryza
|
|
|