|
guyav99 wrote: How do I take the 2 numbers
Console.ReadLine
guyav99 wrote: from different bases
Depends on how you represent them. You can use string parsing methods or int.Parse()
guyav99 wrote: do the addition for example
Convert them to the same base and use +
guyav99 wrote: and present it in a different base?
number.ToString() with a format specifiert should do the trick
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Parse the strings into numbers using the selected base, do the addition, and convert the numbers into strings useing the selected base.
The Convert.ToInt32 and Convert.ToString methods have overloads that handle different bases.
---
single minded; short sighted; long gone;
|
|
|
|
|
OK, lets assume I collected 101 in base 2 into num1 and 75 in base 8 into num2
How do I write the code for the conversion, adding the two numbers and put the result in a base from the user (say $base_result)
|
|
|
|
|
I have told you how to do it and what methods to use for it. Can't you at least make an attempt at writing some code yourself, before asking?
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks for the info, however I'm not sure how to do it.
I looked at MSDN and tried to learn from there but still couldn't understand how to do it.
I wouldn't come to the forum if I knew
|
|
|
|
|
Homework?
Standards are great! Everybody should have one!
|
|
|
|
|
Not at all.
I'm trying to build a calculator that can do multiple stuff and this is one of them.
As you can see, I don't ask anyone to program it for me. This is only a small portion of it.
|
|
|
|
|
Ok, just wondering, sounds like one of my old homework questions. Use String.Format to convert from decimal to hex. You can use int.Parse to get the decimal value back.
Standards are great! Everybody should have one!
|
|
|
|
|
Hello,
Here an example for Hex and int:
public string Int64ToHex(System.Int64 number)
{
return String.Format("{0:X}", number);
}
public double HexToInt64(string hexString)
{
Int64 actint=0;
if(hexString!=null && !hexString.Equals(string.Empty))
{
try
{
actint=System.Int64.Parse(hexString, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture);
}
catch
{
}
}
return actint;
}
I'm using .Net 1.1, so there is no Int64.TryParse, and with double.TryParse it doesn't work.
All the best,
Martin
|
|
|
|
|
|
If you would have gone to class you'ld probably have known...
V.
If I don't see you in this world, I'll see you in the next one... And don't be late. (Jimi Hendrix)
|
|
|
|
|
Hello
I'm looking for a tool for localizing my application. Before entering the .Net world I used gnu GetText, but it doesn't seems to be used for .Net, even though I think it supports it.
I'm looking for a great localization tool, I don't just want to edit the resx file in Visual Studio.
Any suggestion, either open source or below 100$ for a single user license?
|
|
|
|
|
hi all
i want to know how we can find all the text box controls on
a windows form ...
i know how to do it in a web applications but the same logic doesnt workout for windows please help me
for web
ContentPlaceHolder cMainContent = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
|
|
|
|
|
foreach(Control c in this.Controls)
{
TextBox actTextbox = c as TextBox;
if(actTextbox!=null)
{
}
}
-- modified at 7:45 Monday 30th July, 2007
This would be the recursive method which had been suggested by "J4amieC":
private void FindAllTextBoxes(Control c)
{
if(c!=null)
{
if(c.Controls!=null)
{
foreach(Control actControl in c.Controls)
{
TextBox actTextBox = actControl as TextBox;
if(actTextBox!=null)
{
}
else
{
FindAllTextBoxes(actControl);
}
}
}
}
}
All the best,
Martin
|
|
|
|
|
Personally I would have illustrated it differently, mainly by building up a List<TextBox> inside the recursive method.... but your example shows the main ingredients
-- modified at 10:41 Monday 30th July, 2007
|
|
|
|
|
Hello,
J4amieC wrote: but your example shows tyhe main ingredients
Actually, if I have to find out all the members of a type, I mostly hold the references in an ArrayList(.Net1.1) for further usage.
But it really depends on the task.
If he is only searching for one special TextBox instance which is somehow marked (over the Tag property for example), then there is no need for holding all the references, I guess.
All the best,
Martin
|
|
|
|
|
Martin# wrote: If he is only searching for one special TextBox instance which is somehow marked (over the Tag property for example), then there is no need for holding all the references, I guess.
Indeed. Hadn't thought of that!
|
|
|
|
|
Although Martin# has given you a great answer above, remember that Controls are in a heirachy which means that Textboxes could be inside a Panel on the main form, so you might need some kind of recursive function to determine all textboxes on a form
|
|
|
|
|
for(int i=0;i < this.Controls.Count; i++)
{
if(this.Controls[i].GetType() == typeof(System.Windows.Forms.TextBox))
{
MessageBox.Show("textbox");
}
}
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
This code snippet will not find controls based on TextBox;
which "is TextBox" or "as TextBox" do.
|
|
|
|
|
could you please explain it more for me ??
thank you
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
this.Controls[i].GetType() == typeof(System.Windows.Forms.TextBox)
This will not be true for a class descendant of TextBox, that's why.
Standards are great! Everybody should have one!
|
|
|
|
|
thank you very much
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
Hi all, i am trying to delete a row from dataset ,i have used the following code but i am getting error like
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation may not execute.
foreach(DataRow dreach in MailDataset.Tables[0].Rows)
{
if(Convert.ToInt16(dreach["Mailid"])== 37)
{
dreach.Delete();
MailDataset.AcceptChanges();
MailDataset=MailDataset ;
sd1=MailDataset.Tables[0].Rows.Count;
//Da.Update(MailDataset);
}
}
|
|
|
|
|