|
Hi,
why we need to use generic class in c#.
reply me,
thanx in advance....
|
|
|
|
|
Type safety. Most of the casts which can cause errors are noticed by the compiler, not the runtime. This means that you will find it more difficult to compile (you'll get either warnings or errors.) Because of this, you won't need to do as many casts. These mean that you spend less time casting, and have to catch fewer exceptions. So speed is also a factor.
|
|
|
|
|
Good answer - can I throw in readability? It does make the resulting code easier to understand as well (or I think so).
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I hadn't thought of that. Readability is another factor, though it doesn't directly affect execution speed
|
|
|
|
|
I am trying to convert clock time to a double, and am getting an error, can someone use another pair of eyes to assist with this. See the code below. Thanks
static void Main(string[] args)
{
string[] timeArray = new string[6]{ "08:17", "15:26", "18:32", "00:46", "10:38", "13:56" };
double[] decTimeArray = new double[6];
for (int x = 0; x < timeArray.Length; x++)
{
decTimeArray[x] = ConvertTime(timeArray[x]);
}
for (int x = 0; x < timeArray.Length; x++)
{
Console.WriteLine(timeArray[x] + " " + decTimeArray[x]);
}
Console.ReadKey();
}
}
public static double ConvertTime(string rawTime)
{
int hours;
int minutes;
double dminutes;
double decimalTime;
string delimStr = ":";
char[] delimiter = delimStr.ToCharArray();
string[] split;
split = rawTime.Split(delimiter);
hours = Convert.ToInt32(split[0]);
minutes = Convert.ToInt32(split[1]);
if (minutes < 7)
dminutes = 0.00;
else if (minutes < 22)
dminutes = 0.25;
else if (minutes < 37)
dminutes = 0.50;
else if (minutes < 53)
dminutes = 0.75;
else dminutes = 1.0;
return decimalTime = dminutes + hours;
|
|
|
|
|
Still at it?
To get a time span expressed as a floating-point number of hours but rounded to a quarter, I would try something along these lines (code not tested):
private double ToHoursButRoundedToQuarter(string s) {
TimeSpan span=TimeSpan.Parse(s);
int minutes=span.TotalMinutes+7;
int quarters=minutes/15;
return quarters*0.25;
}
|
|
|
|
|
Your code makes very little sense to me. Why not use DateTime and/or TimeSpan ?
|
|
|
|
|
This was working, but right now I am getting the following error:
Expected class, delegate,enum, interface, or struct
I am new to c#, and in a class where we are not using the timespan yet, and will not touch on that in this semester. I you could look at the code I have supplied, and maybe help me find the error, that would be great.
Thanks
|
|
|
|
|
|
that's cheating. The challenge is to locate the error (and to get someone else to that for you).
|
|
|
|
|
Lol
|
|
|
|
|
From the code you posted and the error you say you are getting, I think your brackets are off. You should have { } wrapped around your class methods (Main and ConvertTime) and also to enclose them.
|
|
|
|
|
Thanks, that's what I needed, another pair of eyes. I must have deleted a bracket accidentally. Runs fine now.
|
|
|
|
|
I am a beginner at C# and have been given an assignment that I am having trouble starting. Any help would be useful! Here is the project:
Write a program to print all combinations of hours, minutes and seconds in military time format HH:MM:SS using nested loops.
Like I said, I'm new to this, only 2 weeks in... so keep that in mind!
Thanks,
Bonnie
|
|
|
|
|
It often helps very much when trying to get help with homework assignments if you show what you have come up with so far.
Do you know what nested loops means? Have you given that a try, and if so how far did you get?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
the problem is, with all those nested loops, the app is taking all day.
|
|
|
|
|
Groan.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Nested loops, yes. You'd need 3.
Choosing the bounds of these loops is trivial.
As to outputting, where do you want them to go?
System.Console.WriteLine("{0}:{1}:{2}", h, m, s);
(warning: untested)
Seems reasonable to me.
|
|
|
|
|
It's almost as if the answer is written in your question. If only a certain part were written in all lower case and there was a DateTime object that supported addition your problem would be solved.
|
|
|
|
|
Hi All,
I'm developing a software for geostatistical modeling, and I need to visualize 3d spatial data and doing some basic 3d actions e.g rotation, zoom, slicing, color mapping, gridding and so on. What is the best way for doing this? Shall I use a 3rd party control?
|
|
|
|
|
Couldn't you just use OpenGL?
|
|
|
|
|
I'm not familiar with openGL. which one is prefered, OpenGL or DirectX?
|
|
|
|
|
OpenGL, for several reasons - I'll just list a few:
* easy to use inside winforms (even in C#, check the TAO framework)
* if you manage to crash it, windows will still be alive
* easier low-level manipulation of eg vertices (good for visualization)
* full access to all hardware features (the gpu manufacturer will make sure of it)
DirectX isn't "bad" for 3D visualization though, it's fine to use it.
|
|
|
|
|
Is there any free openGl control implementing basic actions for .NET or I have to design one by myself?
|
|
|
|
|
The TAO framework has one
|
|
|
|