|
Hi Luc,
Thanks for the excellent response. I will do as you suggest.
Regards,
Johnny
|
|
|
|
|
Hi, I am working on a project on Windows Azure Platform....
Does anyone know any good tutorial on this platform?
I want to make a project via Azure Services Developer portal and I want to publish it so it would be available to everyone...
At last, I'd like to make a project in VS 2008 about Cloud Service Web & Worker role to be published, but I couldn't find a good tutorial-example on how to do that, since I am new to these technologies...
Any help would be appreciated.
|
|
|
|
|
|
|
anyone knows how to compile monodevelop from sourcecode with mingW on windows?
I have mono installed, monodevelop source, and mingw installer but I don't know how to use it
Thank's
(sorry if i posted in wrong place, I don't see other place fit)
No one can prevent me to learn something
|
|
|
|
|
Type.GetType("System.Enum").IsClass returns false, yet all the documentation indicates that System.Enum is a class. What am I missing?
|
|
|
|
|
You're not missing anything, it's just that the documentation isn't very consistent in the use of definitions.
IsClass is false, as System.Enum inherits from ValueType . You needn't instantiate an enum, like you would do with a 'real' class.
An enumeration is a named constant whose underlying type is any integral type except Char. If no underlying type is explicitly declared, Int32 is used. Programming languages typically provide syntax to declare an enumeration that consists of a set of named constants and their values.
Enum provides methods to compare instances of this class, convert the value of an instance to its string representation, convert the string representation of a number to an instance of this class, and create an instance of a specified enumeration and value.
It's the phrase "provides methods to compare instances of this class" that makes it harder to explain. You don't make (new ) instances of an enum, you assign it's value to a valueType . Alas, the thing that you are assigning is an instance of a valuetype.
See, speech is mainly for communication and not for the errorless movement of ideas. That's why lots of casual talk is misinterpreted, as both sender and receiver use different versions of the definition of the data that is transmitted
Ehr..
..the short answer was that an enumeration is not a class
I are troll
|
|
|
|
|
MSDN also wrote (on the same page you cited):
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract <big>class</big> Enum : ValueType, IComparable, IFormattable, IConvertible
When I right-click on Enum in a source window in VS and choose Go To Definition it also indicates it's a class:
using System.Runtime.InteropServices;
namespace System
{
[Serializable]
[ComVisible(true)]
public abstract <big>class</big> Enum : ValueType, IComparable, IFormattable, IConvertible
{
members snipped ...
}
}
The Object Browser in Visual Studio isn't sure what it is. Sometimes it thinks it's a struct and sometimes an abstract class.
The bottom line? I'm still not convinced one way of the other.
|
|
|
|
|
It seems that there's indeed an abstract class for working with the structs. If you declare an enum, you're actually inserting named numbers;
MSDN wrote: An enumeration is a named constant whose underlying type is any integral type except Char.
..and then I ran into this post[^] from Brad Abrams, stating that both System.Enum and System.ValueType are implemented as reference-types.
If I understood it correctly, then there's a difference between the abstract System.Enum class and the declared enum that is based on a underlying type?
I are troll
|
|
|
|
|
I think enum values are treated like boxed ints by default, although IIRC it's possible to use other types for the values. Whatever it is there's runtime type information available to know what enum type the value belongs to.
And we're allowed to cast between enums in the somewhat optimistic hope that their underlying values correspond.
This much can be shown by running the following simple application (requires you to create a new windows forms app and drop a button on the form and wire up the click event, as I don't include the designer.cs file here).
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
enum en { Zero, One, Two, Three };
enum fr { Nul, Un, Deux, Trois };
void foo(object obj)
{
if (obj is en) dbug("en:{0} => fr:{1}", obj, (fr)obj);
else if (obj is fr) dbug("fr:{0} => en:{1}", obj, (en)obj);
else dbug("?:{0} => en:{1}, fr:{2}", obj, (en)obj, (fr)obj);
}
void dbug(string s, params object[] args)
{
if (args.Length > 0) s = string.Format(s, args);
Debug.WriteLine(s);
}
void button1_Click(object sender, EventArgs e)
{
Random r = new Random();
for (int i = 0; i < 20; i++)
{
object v = r.Next(4);
if (r.Next(100) < 33)
foo((en)v);
else if (r.Next(100) < 50)
foo((fr)v);
else foo(v);
Thread.Sleep(500);
}
}
}
|
|
|
|
|
|
OK. Given that System.Enum is declared as public abstract class Enum : ValueType, IComparable, IFormattable, IConvertible , in your opinion, what should the following return?
Type.GetType("System.Enum").IsClass
Type.GetType("System.Enum").IsInterface
Type.GetType("System.Enum").IsValueType
My guess would be true, false, false when the reality is false, false, false.
As far as I can tell, Enum is the only type declared as a class in the System namespace hierarchy where Type.GetType("type name").IsClass returns false. I'm trying to find out why, and nothing I've read so far has answered that question.
BTW, not everything derives from Object . Interfaces do not derive from anything.
|
|
|
|
|
Adrian Cole wrote: I'm trying to find out why, and nothing I've read so far has answered that question.
We've already answered that. All value types return false for IsClass, just as the documentation specifies; that's why.
Anyone can write a class that derives from ValueType and it will do the same thing, there just aren't that many times where you want a value type that isn't a structure. Enum is one such case because it also has to be abstract, there's no way to make an abstract structure, so they made it an abstract value type class.
|
|
|
|
|
Yeah, I guess I was just too stubborn to have it sink in. For those that care, creating a class that derives from System.ValueType isn't allowed ... 'TestNamespace.TestClass' cannot derive from special class 'System.ValueType'.
|
|
|
|
|
Hello,
Recently I've decided to rewrite some of my C# code to F# (pratice, learn, maybe move and optimize some code for future). Unfortunately I've faced few problems.
Let's say I have a c# class that looks like this:
public class MersenneTwister : Random
{
private const int N = 624;
private uint[] mt = null;
public MersenneTwister(uint seed)
{
mt = new uint[N]
mt[0] = seed & 0xffffffffU;
for (int mti = 1; mti < N; ++mti)
{
mt[mti] = (69069 * mt[mti - 1]) & 0xffffffffU;
}
}
}
I have no idea how to create constants like N - I could write static let N = 24 but:
- After compilation, c#'s version does replace N with number, as consts should work, f# does not (it uses static field to represent N)
- I can't use static let if I don't have implicit constructor for type, and I can't have one, because my constructor has to implement some code.
I have to create mt array as mutable, but I can't use let (no implicit constructor), if I use member x.mt : uint32 array = Array.create N 0u instead, new array will be created each time I use mt property.
I will be grateful for any ideas.
I also must add that, I can't believe so many people say f# is much more expressive and easier then c#, I'm trying to learn it, but for now, each time I want to do something my way, I have to search informations in books and/or google a lot
|
|
|
|
|
Ravadre wrote: I can't believe so many people say f# is much more expressive and easier then c#
It's more expressive but it is certainly not easier.
Kevin
|
|
|
|
|
I wander - if i write those two lines
a. Object o1;
b. o1 = new Object();
1. In line a - the o1 is initialized to null - is this pointer will be allocate on stack in this place ?
2. when i write "new Object()" ( line b )- is in this step i allocate the new object on the heap ?
Thanks.
|
|
|
|
|
assuming both statements are inside some method:
1. yes the pointer resides on the stack, and no it is not initialized; only class members get initialized to zero/null/Nothing
2. yes
I suggest you buy and study a tutorial book on one of the .NET languages; it will explain it all, step by step, in a systematic way.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
|
one down, a gazillion more to go.
It takes more to stop them all.
O heck, wrong animal, I'll have to keep trying.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Like Luc said, it depends on where you write them.
And o1 is not initialized to anything, meaning it could have Any value (leftover bits from values that used to be on the stack but are now just hanging around), but you're not allowed* to use it (it's an error if you do, will not compile) so you won't see this value.
* well, there is unsafe code. In all the test I did (not that many..) it was just 0 anyway but that's not something I'd rely on.
|
|
|
|
|
Hello I'm a beginner with VB, and I was wondering if someone can help me?
How can you count and display the amount of times that the save button is clicked?
Thank you in advance, Aaron
|
|
|
|
|
AARONDAS wrote: Hello I'm a beginner with VB
Hopefully your plan for learning computer programming is not based on the notion of using internet forums as your source of instructional materials. If it is your plan you should either change it or give up. The choice is yours of course.
|
|
|
|
|
You excel at avoiding words such as buy, book, and study. Ran out of horses?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Actually it's fairly straightforward.
You start with one. Then comes two. Three. Four. Five.
How far do you need to count?
|
|
|
|
|