|
it doesnt work Greeeg. anyway, thank u for ur cooperation.
|
|
|
|
|
Works like a charm for me. I only modified your for loop, the rest has been left untouched:
static void Main(string[] args)
{
int numb;
long fac = 1;
Console.WriteLine("Enter a number :");
numb = Int32.Parse(Console.ReadLine());
for (; numb > 0; numb--)
{
fac *= numb;
}
Console.WriteLine(fac);
Console.ReadLine();
}
-- modified at 17:23 Thursday 9th February, 2006
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Here we go .... i wrote Console.Readline(); without fac... thanx greeeg for ur patience..
|
|
|
|
|
First: here is your code:
<br />
int numb;<br />
long fac = 1;<br />
Console.WriteLine("Enter a number :");<br />
numb = Int32.Parse(Console.ReadLine());<br />
<br />
for ( int numb; numb >0; numb--)<br />
{<br />
fac*=numb--;<br />
}<br />
Now look at what you are doing. int numb; defines a new object numb that is an integer.
numb = blah sets that integer to a number entered by the user.
for (int numb; numb>0; numb--) creates a new instance of numb which (since it is not nullable) gets a new value of 0. So what does your conditional do when it encounters that 0 value? My guess is you always get an answer of 1. Why? (look at it and answer this yourself)
So now you should be able to figure it out...that you need to change your initial storage name (ie. not numb ) then set your for loop value int numb to the value you established in the Console.Read function.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
Hi,
Isnt it possible to declare the array of the size dynamically based on user input. I know i can keep on using Array.Resize() later, but to me, it looks very inefficient that I had to declare some size number at the first time i declare the array. May be I declare it toooo high numbered size so that user will always wont think of that number, but in that case, I am wasting memory for nothintg. When I was coding in PHP or PERL, I did not have to declare size which i enjoyed but here in C#, very disappointing.
|
|
|
|
|
emran834 wrote: When I was coding in PHP or PERL, I did not have to declare size which i enjoyed but here in C#, very disappointing.
No, when you were using Perl, the inefficiency is simply hidden from you; there is no magic way to grow an array without reallocating some memory.
Now, if your array is constantly resizing, you're better off using a list, which gets resized automatically for you:
ArrayList list = new ArrayList();
List<MyObjectType> list = new List<MyObjectType>();
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
Thanks Judah Himango, I got it. Although Little bit harder than those Scripting Languages
|
|
|
|
|
If it's scripting languages you're used to, many of them can be used and compiled to run on the .NET framework (making it instantly interoperable with C# components, VB.NET components, etc.) For example, Microsoft has available IronPython[^] which is Python running on the .NET framework. There is also Perl.NET[^], as well as some interesting new languages such as Nemerle[^] or Boo[^]. JScript.NET[^] is another script language by Microsoft, although it is compiled rather than interpreted.
In any case, the key in understanding scripting languages is that often times performance is sacrificed on the altar of programming ease. You can set a variable to an integer, then set it to a string no problem. That's dynamic/loose typing, which while it makes the life of the developer easier (less typing involved), it also can suffer from performance issues and type mismatch runtime errors (no type safety).
All that said, I would agree that it is too laborious to declare variable types in C#. I see that C# 3 is introducing some new syntax allowing for a more dynamic-like typing, but maintaining performance and type safety via the compiler inferring the type based on usage. For example, C# 3 will allow you to declare an array like this:
var myArray = new {1, 2, 3};
The compiler will infer you're doing an integer array, thus making it equivalent to the more laborious
int[] myArray = new int[] { 1, 2, 3 };
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
Thanks. I am too much habituated to use PHP. Now looks like one day C# will turn to a Scripting type language. By the way, Is C# 3 already available for use in the present Visual C# 2005 Express IDE ? Do I need to upgrade my Framework ? i thought framework 2.0 is the latest one.
|
|
|
|
|
C# won't turn into a scripting language, however, it will certainly borrow some concepts from scripting languages.
C# 3 is available as a pre-beta demo; you can check it out as part of the Microsoft Language Intergated Query (LINQ)[^] package, which includes a pre-alpha C# 3 compiler and extensions to make Visual Studio 2005 work with it (sort of). Unlike C# 2 which, due to generics, required the CLR (.NET runtime) to be modified, C# 3 is has no such requirement and can run on .NET 2.
That said, it's not supported and definitely not ready for prime-time yet, so stick to C# 2 and Visual Studio 2005 (which are both the latest supported releases).
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
If C# will adopt some scripting type functionality, I really really really hope that it will be possible to disable this feature. I would hate to see the compiler starting to make assumptions about my code, like for an example VB does.
If I declare a variable, I want to tell the compiler what data type it should have, I don't want the compiler to make a half-assed guess what data type I possibly could need. For simple taks where the data type doesn't really matter, it might be useful, but for anything more advanced it would only make it more complex. If you specify a data type, it simple. You get what you asked for. If the compiler gets to choose the data type, you will have to know the compiler criteria for choosing the data type in order to know what data type it will be, and every time you get it wrong it's a potential source for bugs.
If you think that programming is too much typing and too little mind work, you are simply not working with projects that challange your potential.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I need to trigger an event handler and pass variable from a Child form to parent form. Can you show me any easy snippet to do that pleaseeee..
EMRAN
|
|
|
|
|
Hi,
I am using Visual Studio .NET 2003 with Framework 1.1.
I downloaded and installed Framework 2.0. Now how do I direct Visual Studio to use Framework 2.0. It is still using framework 1.1.
Thanks.
|
|
|
|
|
If it is the case of Windows application, I think you should use Visual Studio 2005 Express which is built for Faremework 2.0. Visual C# Express is free to download from msdn.microsoft.com and You can convert your existing VS 2003 project to VS 2005 Project easily from that New IDE. To me, the new 2005 Express IDE is really great and way more comfortable.
EMRAN
-- modified at 17:04 Thursday 9th February, 2006
|
|
|
|
|
This was answered earlier today, here[^].
|
|
|
|
|
Hello,
I've posted this question on MSDN forums, but since I'm lost here, I decided to ask here too. I'm sorry for that.
Here's the problem,
I have a custom TreeView with custom nodes as private nested classes in the TreeView.
The TreeView initialize and add some nodes at construction.
Because my classes are quite long, I'll post only a sample to reproduce the problem.
MyTreeView class:
public partial class MyTreeView : TreeView<br />
{<br />
public MyTreeView()<br />
{<br />
InitializeComponent();<br />
<br />
Nodes.Add(new MyTreeNode());<br />
}<br />
<br />
private class MyTreeNode : TreeNode<br />
{<br />
public MyTreeNode() :<br />
base("MyNode")<br />
{<br />
}<br />
}<br />
}
Each time I use this class in a form at design time, the treeview shows with the added custom nodes, but in the form's InitializeComponent(), I get this:
WindowsApplication2.MyTreeView.MyTreeNode myTreeNode1 = new System.Windows.Forms.TreeNode("MyNode");<br />
this.myTreeView1 = new WindowsApplication2.MyTreeView();
Now this won't compile because the node is private to MyTreeView.
Is there any way to prevent the nodes from showing up at design time?
Or am I doing something wrong?
Thanks!
-- modified at 16:19 Thursday 9th February, 2006
|
|
|
|
|
Make MyTreeNode protected public. How else must someone use it? Another option is to create some factory, but the designer will probably break then, then you would have to look at doing your own designer, and by that time I would just not bother... :p
|
|
|
|
|
Thanks for your reply leppie!
I'm afraid it won't work...
The thing is, no one will have to work with the nested nodes except MyTreeView class.
Even if you declare the nodes public, it won't work because when I use the TreeView in an editor, it will try to create the nodes for me. And there's no conversion from TreeNode to MyTreeNode.
So the line that appears on the form's editor (where I use the control) won't compile:
WindowsApplication2.MyTreeView.MyTreeNode myTreeNode1 = new System.Windows.Forms.TreeNode("MyNode");
Now this could be easly solved if I knew how to tell "Don't run this while in design time". Since I don't need it at all at design.
Thanks!
|
|
|
|
|
A good guy on microsoft newsgroups gave me the awnser!
So, for the records, the solution is hide the Nodes property of the TreeView class and apply these attributes:
[Browsable(false)]<br />
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]<br />
public new TreeNodeCollection Nodes<br />
{<br />
get<br />
{<br />
return base.Nodes;<br />
}<br />
}
Now the custom nodes won't show on designer.
|
|
|
|
|
hello, i'm working on a project where i need make use of a customised (non-rectangular) window form, and i'm having trouble pinning a menu bar to it. my menubar is displayed a few milicentimetres above the windows form leaving a gap between itself and the form eventhough it is attatched to it. i.e. moves, minimizes and closes with the form. can anyone help me out on how to get this done? the way it should be on a proper windows form..... thanks alot......
dlinks
|
|
|
|
|
Hello,
I am using .NET 2.0, and I have a string "4.0000". I want to convert that string to int, and I am using: Convert.ToInt32("4.0000").
Problem is, that gives me an error, while in the previos version of .NET environment everything was fine. Any ideas?
Thank you.
|
|
|
|
|
Why not just do Convert.ToInt32("4")?
Andy
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
I am pulling the data from the server.
|
|
|
|
|
Try converting to a double or float, then cast it to an integer.
|
|
|
|
|
Don't use Convert.ToInt32 use Int32.TryParse() instead.
|
|
|
|
|