This question already has answers here:
What's the difference between [Something] and [SomethingAttribute] [duplicate]
(3 answers)
Closed 7 years ago.
I hope this wasn't asked already. But i found nothing. If something exists, thanks for the note.
The title says it all i think.
I've seen these two variants. But in my opinion it does the same. And why can i use both. Thanks for education.
// variant 1
[ContentProperty("Text")]
// variant 2
[ContentPropertyAttribute("Text")]
You can omit the word "Attribute" when writing attributes over something. The actual class is called ContentPropertyAttribute. Both of your lines do exactly the same and use the exact same attribute class.
Related
This question already has answers here:
C# Empty Statement
(13 answers)
Closed 5 years ago.
I've come across this example of an empty statement in a C# textbook.
Code:
public void empty()
{
;
}
Some quick googling found that it's a redundant feature and I can't see the use of this as it seems pointless?
I was curious to know when this would've been useful and if it's still used to date even though it's obsolete?
In the given example it is pointless and/or cosmetic.
The empty statement is "useful" in places where a statement is required but you have nothing to do, like
while (condition_with_side_effects) ;
Because of the side effects required, this will not match with most coding guidelines or best practices.
Consider it a leftover from C.
This question already has answers here:
What is the difference between Convert.ToBoolean(string) and Boolean.Parse(string)?
(3 answers)
Closed 6 years ago.
Why do Boolean.TryParse() and Convert.ToBoolean() evaluate a string differently?
I understand how they end up evaluating differently:
Boolean.TryParse() will match (case insensitive) 'true' and 'false'.
Convert.ToBoolean() will match to a whole range of values (example demonstrated in Microsoft doco linked above) which I would consider more natural.
Its the reasoning behind the difference I dont understand.
There are a couple of discussions touching on this subject which don't seem to address this particular question.
It's in the method/class names.
Convert -> you already have some value, you convert it to another type. e.g. you have value 1 which can be converted to true.
Parse -> you have the value as a string and you parse it.
This question already has answers here:
What is the use of static variable in C#? When to use it? Why can't I declare the static variable inside method?
(12 answers)
Closed 7 years ago.
Does anybody know how to modify a static variable from a different script in Unity?
Please, provide more information about how are you trying to do this...
If you need to change between mono behaviours, for example, you will need to get current instance of behaviour you like to change in a way like
myGameObjectInstance.GetComponent<MyBehaviourWithStatic>().myStatic = value;
but note that user2320445 answer is not wrong, it depends on your context. Be more specific on your question and we could provide better and precise answers
This question already has answers here:
Application.ProductName equivalent in WPF?
(7 answers)
Closed 8 years ago.
Is there something similar to the following property in WPF?
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.productname(v=vs.110).aspx
Thanks.
Not that I know of. But you can easily create this method yourself.
The actual code used by WinForms has several levels of fallback: it first look for an AssemblyProductAttribute on the assembly defining the control, then at the file version and finally falls back to the first part of the namespace.
You can copy that logic (or the parts that are relevant to you) directly from .net source code: http://referencesource.microsoft.com/#System.Windows.Forms/ndp/fx/src/winforms/Managed/System/WinForms/Control.cs#f7c944851a004a6e
This question already has answers here:
What does square bracket [] mean in the below code?
(2 answers)
Closed 8 years ago.
Hello, can you please explain me what is the significance of [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("activityid")] in the following code?
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("activityid")]
public Microsoft.Xrm.Sdk.EntityReference ActivityId
{
get
{
return this.GetAttributeValue<Microsoft.Xrm.Sdk.EntityReference>("activityid");
}
set
{
this.OnPropertyChanging("ActivityId");
this.SetAttributeValue("activityid", value);
this.OnPropertyChanged("ActivityId");
}
}
I searched for this thing and I got many posts which gave me answer as the ones in square brackets are Attributes in C#. But, then attributes are related with methods. Over here, ActivityId doesn't seem to be a method. So, how can [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("activityid")] act as an attribute?
Is it related to C# or it has got something to do with CRM?
The confusion comes from your statement about attributes only being valid on methods. Attributes can be valid on items specified in the AttributeTargets enum:
http://msdn.microsoft.com/en-us/library/system.attributetargets.aspx
This then puts you back to the answer being "they are attributes". That attribute has simply been applied to a property.