Link to home
Start Free TrialLog in
Avatar of Arnold Layne
Arnold LayneFlag for United States of America

asked on

Easy C# question about Guids

I am taking SharePoint dev courses about SP workflows and the assumption is that I have already mastered C#, which i have not, I only have a decent understanding of the principles. So the course keeps on pulling a rabbit out of a hat, so to speak, without explanation. So I might have many more questions like this ion the future, but hopefully they will all be easy points for everyone.

I understand what default(Guid) does after some research, and the course code used this in another exercise
public Guid varname = default(Guid);

But now in this exercise, when it is declaring a field to hold a Guid value it is:
public Guid workflowId = default(System.Guid);

At first I thought it needed System.Guid instead of just Guid because I have no using statement at the top for System.Guid, so in this case, it has to be explicit. So when I went to add using System.Guid, intellisense does not know what I am talking about. I have read that Guid is in the System namespace, so I thought that maybe I need to add a reference to System.Guid, but under .net, I cannot find any such reference.

So what's going on?

Also, inside of an event handler, it calls this
taskID = Guid.NewGuid();

I understand that the Guid has a static method called NewGuid, which does not create an empty guid like in the case of the field variable declaration above, but instead generates an actual Guid value. But I don't understand how this method could just seemingly be called out of nowhere right after a Guid value type. Does it have something to do with the fact that taskID has already been declared as a Guid field/variable?
SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arnold Layne

ASKER

Thanks guys. It looks like it doesn't even need default(System.Guid) and default(Guid) seems to build fine, so maybe it's just a redundancy in the course's code as it's not really the best course in the world, but it's cheap. what they did was not wrong, it just wasn't necessary. As far as a using statement, apparently "using System;" itself takes care of it after what I have just read, even though it is in the mscorlib.dll. But when i go to add mscorlib.dll to the references, it tells me that this will be added at compile time, so it does not add it.

As far as Guid.NewGuid, the leading Guid threw me off, but I suppose that this is the same thing as saying String.Empty, so i can just look at it that way, where if you call a static method of a class, you have to refer to the class itself first.

Thank you much. I may have many more questions following, and hopefully they are all easy for anyone like this one was. Microsoft does technically have these explanations, but they aren't very explicit and while I can often figure the explanation out myself, I sometimes cannot and need some confirmation.
Correct on one thing. The code was System.Guid because one instance of this was automatically populated by default by VA, and the other was generated by the auto field builder when one is binding something to a field, so i guess that any auto builders try to be as safe as possible and make no assumptions, so it is System.Guid rather than just Guid Either way, apparently it is the same thing.
As far as Guid.NewGuid, the leading Guid threw me off, but I suppose that this is the same thing as saying String.Empty, so i can just look at it that way, where if you call a static method of a class, you have to refer to the class itself first.
Correct.