Solved

Easy C# question about Guids

Posted on 2013-11-07
5
409 Views
Last Modified: 2013-11-08
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?
0
Comment
Question by:BobHavertyComh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
ID: 39630382
You would need System.Guid if you didn't have a "using System;"  statement.  If you have the using statement, you should just be able to refer to Guid as you normally would.  The using refers to the namespace (eg: system) . . . and then you get access to all classes in that namespace by default.


Just a note on one of the most useful tricks I've ever learned.

Type this into your page (remove references to system.Collection if it's there):

        Thread x;

Click back on the word "Thread"

Hit ctrl + period

This will automatically ask you whether you want to add the using statement or change the list to be the fully qualified name . . . very useful if you're trying to find out where something is coming from.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 39630388
Admittedly, I have no SP development experience. Based on what I read above:

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.
That is correct.

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.
Try mscorlib.dll.

But I don't understand how this method could just seemingly be called out of nowhere right after a Guid value type.
As long as you declared the variable somewhere before you attempt to use it (e.g. assign to it), then you can use it. So...

Does it have something to do with the fact that taskID has already been declared as a Guid field/variable?
...yes.
0
 
LVL 9

Author Closing Comment

by:BobHavertyComh
ID: 39633879
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.
0
 
LVL 9

Author Comment

by:BobHavertyComh
ID: 39633941
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.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39633951
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question