|
Thanks sir for your reply. Even I know its most generic error. my code is simple like
WorkItemType workItemType = teamProject.WorkItemTypes["Task"];
for(int i=0;i<100;i++)
{
WorkItem task = new WorkItem(workItemType);
task.Fields["somefield"].Value = "somevalue";
task.save();
}
exception comes at task.save. and value of I varies some times 2, some times 4 even some times it reaches 60.
|
|
|
|
|
I have no idea what's causing the problem as I've never done anything in code with TFS.
|
|
|
|
|
I want to calculate the size of the variable and not size of the data type. For example int anyValue=10;
what is the size of anyValue ?
(*Not calculate size of int)
NOTE:-->
So here anyValue size must be less from int datatype size.
|
|
|
|
|
You could do it by a loop that repeatedly right shifts the value until it reaches zero. The number of shifts gives the size.
|
|
|
|
|
Have a read of this Marshal.SizeOf[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
The size of a variable is the size of the type it declared as: so for your example:
int anyValue = 10; the size of anyValue is always 32bits / 4 bytes because an int is a fixed size, regardless of what it contains.
This is even true for reference types: the variable which holds the reference will always be the same size:
Control c = button1; c is a reverence to a Control instance, so it will always be 32 bits or 64 bits depending on your your app is built and running.
The value it refers to can be different sizes in some cases: string, arrays, collections and so on can be variable sized1, but in general even a specific instance of a class will always be the same size. Value type instances are always the same size, they can't vary.
1: Even then, the collection instance is not a variable size, but the data it collects may be - the actual collection of objects is stored as an array of objects which is itself a reference.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi OriginalGriff,
int sizeOfVariable = Marshal.SizeOf('A');
int size = sizeof(Char);
Console.WriteLine("The size using marshal is {0} and SizeOf is {1} ",sizeOfVariable,size);
Console.Read();
Why the two result is different ??? :P
|
|
|
|
|
sizeof vs Marshal.SizeOf[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is where is starts to get complicated...
Because a Char is not the same everywhere!
'A' is a char - so it will normally return 2 because a Unicode character takes two bytes (an ASCII character takes one, but nearly all the time in .NET you are dealing with Unicode values)
So the sizeof(char) returns 2 because it needs two bytes of managed memory to store each char.
When you use Marshalling however, it isn't dealing with Managed memory, so it doesn't use Unicode - it uses ASCII instead. Because Marshalling is all about getting ready to talk to external non-NET applications, it can't just pass managed memory directly - because it might have to move it while the other application is using it - so it will effectively prepare a copy of the data in ASCII, because that is the older character standard that most apps used pre-NET.
So sizeof will give you the Managed size - 2
and Marshall.SizeOf gives you the unmanaged size - 1
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi OriginalGriff
Yess This is right Boss
|
|
|
|
|
What definition of "size" are you using here? Because normally it would be said that the size of anyValue is by definition the size of its type, it's a fixed-size type after all.
|
|
|
|
|
public interface IWTF
{
string SomeString { set; get; }
}
public static class WTF<T> where T : IWTF
{
public static string WTFMethod(IWTF i1, IWTF i2)
{
return i1.SomeString + i2.SomeString;
}
} Given the above: in some Method, in some instance-of-something-or-other, you call the 'WTFMethod in 'WTF:
WTF.WTFMethod(null, null); Of course, an error would be thrown as the 'WTFMethod was executed.
Which means (?): if I really want to make sure that I'm getting valid parameter inputs to 'WTFMethod:
public static string WTFMethod(IWTF i1, IWTF i2)
{
if (!(i1 is IWTF) || !(i2 is IWTF)) throw new ArgumentException("You Suck !");
return i1.SomeString + i2.SomeString;
} This lack-of-strong-typing (I don't know what else to call it) became apparent to me today while testing an Interface and its implementations.
Why ?
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
I assume in your second code block the generic type got lost while pasting it?
I can't see anything abnormal here - the compiler allows you to provide null for any reference type argument. The argument being an interface type doesn't matter.
But null is the only other possibility aside from a valid IWTF-reference, so you can replace the (i1 is IWTF) -checks with checking for null/non-null.
cheers, Sascha
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Hi, I'm new in C#, first of all sorry for my bad english.
I have a form, there is a login and a password input in my form.
I want to make a update query in a virtual machine, just a sample (I know the code isnt right):
UPDATE 'launcher' = 0 WHERE 'account' = textbox.Text and 'login' = textbox2.Text
--
So, whow can I make this? I know that to have privilegies I have to execute this from a php inside the machine where is the sql table.
Like my title says, I want to send the values account and password to a PHP in online machine, and that executa the query.
|
|
|
|
|
You have to send a HTTP Request to the machine where the web application is running. Construct the URL correctly, then send it, and collect the response. E.g.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
|
|
|
|
|
Thanks, if your type I found the solution in Internet!
|
|
|
|
|
Initially , I did row grouping in excel document using c#. Again I perform row grouping in between the (already grouped rows). same excel document the outline level will be increased.
I use below code
Excel.Range rng2 = sheet.get_Range((rg_row1 + 1) + ":" + (rg_row2 - 1), Missing.Value) as Excel.Range;
rng2.EntireRow.Group();
Please tell me why that outline level is increased?
How to maintain 2 levels?
|
|
|
|
|
I want clear understanding.
|
|
|
|
|
|
Just to add, the second example there is rather ambiguous.
Rather than having object , if you modify the code slightly to use string (string is still a reference type) as:
string name = "sandeep";
char[] values = {'s','a','n','d','e','e','p'};
string myName = new string(values);
Console.WriteLine("== operator result is {0}", name == myName);
Console.WriteLine("Equals method result is {0}", myName.Equals(name));
Console.ReadLine();
This is due to the CLR String pool -> the strings with same content reference to the same memory.
Just saying, if that interests the OP.
You have just been Sharapova'd.
|
|
|
|
|
It might be wise to call ReferenceEquals on your two strings to prove the point, or not, as the case may be.
Alan.
|
|
|
|
|
Yeah, sorry. I really should have mentioned about interned strings.
You have just been Sharapova'd.
|
|
|
|
|
Always(== and .equals) do value comparison in case of String datatype.
in case of other reference type == produce reference comparison and .Equals compares value or content.
In value types data both act same and compares value only
After Some RND I found this.
If its not 100% right please explain why
|
|
|
|
|
“==” compares if the object references are same while “.Equals()” compares if the contents are same.
So if you run the below code both “==” and “.Equals()” returns true because content as well as references are same.
Take 2 variables & test it ,you came to clear conclusion....
|
|
|
|
|
There are many differences, I'll list only some of them..
Equals is a virtual function that is present in Object, whereas operator== is a static function. Many of the differences arise from this. For example (not an exhaustive list),
- there is by default no operator== for a value type, where there is an Equals inherited from Object.
- you can use Equals on a value that has any generic type, you can use operator== only if the generic type is constrained to be a reference type (and then it will mean reference equality, not any operator== defined by whatever the concrete type was).
- an overridden Equals must deal with a parameter of type Object, an implemented operator== can decide for itself what types its parameters must have (at least one of them must be the same as the declaring type though).
Together this usually (but not always) means that implementing operator== is confusing for a reference type, but expected and wanted for a value type.
They also have slightly difference meanings in general, operator== can be "whatever makes sense", but Equals should be an equivalence relation, because it (or its cousin, IEquatable<sometype>.Equals) is used all over the place in the standard library and third party libraries with the assumption that it is an equivalence relation. Violating that will cause trouble if, for example, you use it as a key in a Dictionary<Tkey, Tvalue>, or if you try to put it in as HashSet<T> (which various parts LINQ like to do behind the scenes, breaking unexpectedly and invisibly if Equals is not an equivalence relation).
Usually operator== should (for sanity) also be an equivalence relation, but it isn't always, for example take double.NaN, which must be equal to itself according to Equals (equivalence relations must be reflexive), but compares unequal to everything (including itself) according to operator==. If it didn't compare equal to itself according to Equals, putting it in a HashSet<double> would result in it "never really being present" (it would be added, but testing whether it is in there would return false), so thankfully that is not how it works. Meanwhile it should also compare unequal to itself, otherwise it would be in blatant violation of the IEEE 754 standard for floating point arithmetic.
|
|
|
|