|
No it's not. It is a statement delimiter. However, normally you don't have more than one statement per line.
|
|
|
|
|
That's nit picking. You know what I meant. When someone says 'do this in 'x' lines', concatenating logical lines, which makes code harder to read, doesn't count.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
public static string wordReverse(string s) {return string.Join(" ",Array.Reverse(s.Split(" ")));}
public static string wordReverse(string s) {
string[] sa=s.Split(" ");
Array.Reverse(sa);
return string.Join(" ",sa);
will reverse the order of words when word=sequence of chars delimited by spaces;
it will fail for sentences having punctuation (your example has none), they would
require a lot more code to get handled correctly in all cases.
public static string wordReverse(string s) {return string.Join(" ",Array.Reverse(s.SubString(0,s.Length-1).Split(" ")))+s.SubString(s.Length-1);}
public static string wordReverse(string s) {
string[] sa=s.SubString(0,s.Length-1).Split(" ");
Array.Reverse(sa);
return string.Join(" ",sa)+s.SubString(s.Length-1);
which preserves the final punctuation, assuming one is present.
And you could add a test to see if the final character is one of ".;:?!" to choose one
or the other. LastIndexOf could help here.
-- modified at 16:01 Thursday 22nd November, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks Luc,
Hopefully in a few years i'll be able to code like you and someone might want to hire me
Mark.
|
|
|
|
|
Hi Mark,
don't give up; if you ask me such a test is plain silly, they should look
for analytic and synthetic power, logic, energy, thoroughness, not fancy coding.
Anyhow experience and study will guide you.
Read some books; study some CP articles. And yes, read up on the important classes, one by one,
so you get a good grip on their functionality, not their details.
BTW: how will I receive my 100 pts?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: how will I receive my 100 pts?
Here you go, Luc:
Point[] pts = new Point [100];
/ravi
|
|
|
|
|
Many thanks.
Yet another collection I can reverse...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Wow, the for loops i could have avoided had i know about Array.Reverse()
Good job i've only ever reversed an array once
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
C# 3 (the version that will be released within a month or two) has a feature called extension methods that allow you to do something like you'd see the Ruby version do.
Because of generic extension methods, you can do this in C# 3:
string Swap(string input)
{
return input.Split(' ').Reverse().Aggregate((first, second) => first + " " + second);
}
Now, that's doing it all in 1 line and it's not too bad. That said, you might want to comment it, break it up, and make it easier for humans to read. Something like this might be more readable to humans:
string Swap(string input)
{
string[] words = input.Split(' ');
IEnumerable<string> reversedWords = words.Reverse();
return reversedWords.Aggregate((first, second) => first + " " + second);
}
|
|
|
|
|
hi,
i have a managed library(not application) that requires some unmanaged dlls, is there a way to emmbed a manifest or some other way to make it "xcopy distributable"?
* the problem is that the unmanaged dlls reside with the lib and not the application.
|
|
|
|
|
I feel like this should be obvious, but I haven't found it yet. Does anyone know how to get a Property Grid to display an int or byte property value in hex?
"We may not be the smartest in the world, but we're the smartest you've got."
-a co-worker, speaking to our manager
|
|
|
|
|
Call ToString("X") on your int/byte variable to return a string representation of its value in hexadecimal format.
Paul Marfleet
|
|
|
|
|
To be a bit more precise, do this kind of conversion in a TypeConverter (a converter derived from Int32Converter for example) ConvertFrom/ConvertTo methods and attach this converter to your property thanks to the TypeConverterAttribute.
|
|
|
|
|
Thanks for the help. I was hoping that I could set a property on the PropertyGrid to show all of the objects integer types as hex (like in the watch display in the debugger), but I'll proceed with the TypeConverter.
Regards.
"We may not be the smartest in the world, but we're the smartest you've got."
-a co-worker, speaking to our manager
|
|
|
|
|
|
Here we go...that should have been for the lounge, so I deleted it - just as you answered....so....nobody knows what you are apologising for....but I forgive you...
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
See... now I seem mysterious
|
|
|
|
|
I need to get a list of domain names hosted on an ip address ..
is that possible ..
some one told me that it can be done using TelNet
Thanks in advance, I really appreciate your help in any way.
|
|
|
|
|
Definately not with telnet. I don't think you can do this. What you need to look at is the virtual servers configured on the IP's webserver. That information is not accessable to any other then the administrator of that machine so I don't think what you are asking is doable.
|
|
|
|
|
Not really 100% sure what you are looking for but try the following from the command line.
nslookup ipaddress
Mike Lasseter
|
|
|
|
|
Hello!
I'm pretty new to C# and this is a newbie question, so I'm sure I can get help
I get the following message when I try to run the program in Visual C#: "The name 'rightAnswer' does not exist in the current context".
Anyway, here's the code:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace Multiplikation<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
public void getQ()<br />
{<br />
Random r = new Random();<br />
int maxRand = 9;<br />
int firstNumber = r.Next(maxRand);<br />
int secondNumber = r.Next(maxRand);<br />
label3.Text = firstNumber + " * " + secondNumber;<br />
int rightAnswer = firstNumber * secondNumber;<br />
}<br />
<br />
public void button1_Click(object sender, System.EventArgs e)<br />
{<br />
int theRight = rightAnswer;<br />
<br />
int answer = int.Parse(textBox1.Text);<br />
<br />
if (answer == theRight)<br />
{<br />
label4.Text = "Right answer!";<br />
}<br />
<br />
else<br />
{<br />
label4.Text = "Wrong Answer!";<br />
}<br />
<br />
getQ();<br />
}<br />
<br />
}<br />
}<br />
|
|
|
|
|
The variable 'rightAnswer' is only local to the method getQ()
And you can't access it from anywhere else.
Add a class variable or something, so you'd end up with:
public partial class Form1 : Form
{
private int rightAnswer;
...
public void getQ()
{
Random r = new Random();
int maxRand = 9;
int firstNumber = r.Next(maxRand);
int secondNumber = r.Next(maxRand);
label3.Text = firstNumber + " * " + secondNumber;
rightAnswer = firstNumber * secondNumber;
}
public void button1_Click(object sender, System.EventArgs e)
{
int answer = int.Parse(textBox1.Text);
if (answer == rightAnswer)
{
label4.Text = "Right answer!";
}
...
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
First, please use the <pre> tags to format large code blocks like this.
From the nature of this question, it would appear that you're pretty new to programming and not just C#. Do you understand what the compiler error is saying in "plain english"? "Scope" essentially refers to anything inside a { } pair, so the class forms one scope and each method inside that class forms another scope (each method is it's own scope). Scope is limited as you go further into the class, so things inside a method are not visible to things outside of the method.
As long as you understand that concept, if you take another look at your code you should see the following things (as they relate to your error message):- The variable
rightAnswer is defined inside a function named getQ .
- The function
button1_Click tries to use the variable rightAnswer
Given the rules of scope I mentioned, the variable is only defined within the getQ method and is not visible outside of that method.
In order to do what you want, the variable must be defined outside of any methods, but inside the class, which gives it a "class-wide" scope. Since it is defined at a higher scope, it is visible to any methods defined. Generally, class variables like this are defined at the top of the class (just under the public partial class Form1 : Form line but before the constructor.
|
|
|
|
|
Hi,
What Installation System do you recommend the most? Do you know of any side-by-side comparisons of the big ones out there (I searched for a while with no luck)? Currently my company uses InstallShield but we're looking into moving into an OpenSource installer (probably Inno or NSIS) and I was wondering if there were any clear cut advantages to one installer vs the other (No one here has any experience with either one). Thanks.
|
|
|
|