|
Hi!
I am creating ErrorProvider objects with new in my code (and calling SetError(...)) while validating a form. It is also added to a List<errorprovider> Later on I call Clear() and remove the reference in the List. Will the object be garbage collected after that or am I piling up a lot of never-used ErrorProvider objects?
ErrorProvider errProvider;
List<ErrorProvider> errProviderLst = new List<ErrorProvider>();
...
errProvider = new ErrorProvider();
errProviderLst.Add(errProvider);
errProvider.SetError(c, "Ange ett heltal");
...
errProviderLst[i].Clear();
errProviderLst.RemoveAt[i];
|
|
|
|
|
If there are no other references to the object, then yes, when it loses scope. Implement IDisposible and have it write something to the debug output-window to verify
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I want to know that what is get and set Property in C#,
and what is difference between them???And if i want to use only get Property then how can i do this in code???
Can any one help???
What is the use of get and set property,and why we have to use get and set property and which condition???
modified 18-Sep-15 3:19am.
|
|
|
|
|
|
Property get lets you retrieve the value of the property by calling a method to evaluate the property's current value, with syntactic sugar to make it look like a variable.
Property set does the same thing, but it allows you to set the value.
For example, your class may store the user information as "first name" and "second name" internally, and provide a Property FullName:
private string firstName = "";
private string lastName = "";
public string FullName
{
get { return string.Format("{0} {1}", firstName, lastName); }
set
{
string[] parts = value.Split(' ');
if (parts.Length != 2) throw new ArgumentException("Full name requires a first and last name: " + value);
firstName = parts[0];
lastName = parts[1];
}
} To provide a getter only is easy - there are two ways:
public string MyProperty { get { return "Hello"; }}
Requires no setter.
Or you could have a private setter:
private string _MyProperty = "Hello";
public string MyProperty
{
get { return _MyProperty; }
private set { _MyProperty = value; }
} This allows your class to set the value, but the outside world can only see the getter.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
a small example on top of the previous answers.
Think of a car, it has properties like color, max speed, current speed, number of wheels, ...
A car can also do stuff like accelerate, turn, ...
If you would put this in the code, the properties would be put in variables and exposed via properties (get/set). Accelerate and turn are actions that are translated into methods.
Some properties can only be set when instantiating the class, eg number of wheels and maxspeed. Some can be changed from outside: You can repaint the car eg. Some can never be changed (number of wheels) and some can only be changed by using a method. (Accelerate will change the current speed and a check will prevent it from becoming higher than the max speed property).
The inner workings of properties and methods are never exposed. eg. the check where the current speed is never higher than the max speed could reside in the accelerate method or in the current speed property itself.
Read up on "encapsulation" for more info.
Hope this helps.
|
|
|
|
|
At the risk (to my immortal soul) of appearing to re-write code by my esteemed mentor and colleague, OriginalGriff, I'd like to add that there is almost a "standard practice" in the use of Properties in .NET, for example:
public class Employee
{
public Employee()
{
}
public void SetEmployeeName(int authorizationcode, string fname, string lname)
{
if(AuthorizeOkay(authorizationcode)
{
FirstName = fname;
FamilyName = lname;
}
else
{
NotifyUnauthorizedAccess(authorizationcode);
}
}
private string _firstName;
public string FirstName
{
private set { _firstName = value; }
get { return _firstName; }
}
private string _familyName;
public string FamilyName
{
private set { _familyName = value; }
get { return _familyName; }
}
public string FullName
{
get { return string.Format("{0}, {1}", FirstName, FamilyName); }
}
} Notes:
1. the variables declared 'private which begin with an underscore character "_" are called "backing fields."
2. the fact that all the 'get methods in the properties are public allows access by all.
3. the use of private 'set methods insure that the data can be changed only using the publicly exposed 'SetEmployeeName method.
4. the code shows a simulation in pseudo-code of the use of an "authorization code" to illustrate the idea that some vital information may be protected from "unauthorized" access. I'm not saying you "should" do anything like that, just suggesting the possibility.
You might be asking why there are separate properties for first-name and family-name; consider you have a million records and you want to search for duplicate employee last names: possibly, easier to do with only one "field" to search in each record.
Sure, there are lots more "bells and whistles" you could add here: for example, testing in the 'SetEmployeeName method for null values in either first, or family, name input strings.
There are tools, like ReSharper, that will let you click on an auto-property name and will create the private backing field and modified set/get methods for you.
«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.
modified 15-Sep-15 7:42am.
|
|
|
|
|
Lets consider table 1 contain 30 column and table 2 is 30 column.i want to compare values one by one with respect to column name.eg.Table 1 column are A,B,C.. and Table 2 Column A,B,C....And values are xyz,abc,pqr and from table 2 xyz,jkl,pqr.Final result is Right,wrong,right likewise..
|
|
|
|
|
Very interesting, do you have a question?
|
|
|
|
|
Assuming the tables have the same primary key then do an inner join on the PK and compare each field.
Your question is ambiguous, do you want to compare each field in each record, the distinct of each column. try explaining it again in more detail and we may be more useful.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I assume you are talking about C# client side comparing with DataTable object(s).
It that is the case you should check this: www.dotnetperls.com/datatable-compare-rows
|
|
|
|
|
I didn't undersrand this code, is it for both moving polygons, (I said both)
bool AxisSeparatePolygons ( Vector N, Polygon A, Polygon B, Vector Offset, Vector Vel, float &t, float tmax)
{
float min0, max0;
float min1, max1;
CalculateInterval(N, A, min0, max0);
CalculateInterval(N, B, min1, max1);
float h = Offset dot N;
min0 += h;
max0 += h;
float d0 = min0 - max1; // if overlapped, do < 0
float d1 = min1 - max0; // if overlapped, d1 > 0
// separated, test dynamic intervals
if (d0 > 0.0f || d1 > 0.0f)
{
float v = Vel dot N;
// small velocity, so only the overlap test will be relevant.
if (fabs(v) < 0.0000001f)
return false;
float t0 =-d0 / v; // time of impact to d0 reaches 0
float t1 = d1 / v; // time of impact to d0 reaches 1
// sort the times.
if (t0 > t1)
{
float temp = t0;
t0 = t1;
t1 = temp;
}
// take the minimum positive
taxis = (t0 > 0.0f)? t0 : t1;
// intersection time too late or back in time, no collision
if (taxis < 0.0f || taxis > tmax)
return true;
return false;
}
else
{
// overlap. get the interval, as a the smallest of |d0| and |d1|
// return negative number to mark it as an overlap
taxis = (d0 > d1)? d0 : d1;
return false;
}
}
it will only calculate time of velocity to overlap one of them to the other not both, but my exe make the right moment of collision, how that happens in sat? calculate next frame for both and use thales equation, because that's what I do.
from http://elancev.name/oliver/2D%20polygon.htm[^]
|
|
|
|
|
Is this C++ code?
(The float &t is clearly NOT C#)
This is in the wrong forum.
It should be in: C / C++ / MFC[^]
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
anyway I can answer my post, it was the relative velocity, that make the right moment yep
|
|
|
|
|
Hi All,
Greetings!!.
I have got a requirement where in i need to write a C# code which should do the following tasks.
1) Pushing the files from ETL landing zone to Share point site(2013 version).
2) Once the files have been copied a mail has to be send to group of people with that share point URL.
This is a bit urgent.
Hence immediate response along with the step by step source code would be highly appreciated.
Thanks in advance.
Regards,
Nanda Kishore.
|
|
|
|
|
Naga Nanda Kishore wrote: Hence immediate response along with the step by step source code would be highly
appreciated. You are paying as much as the others and are equally important as everybody else; it is not urgent to me.
Having an alert mailed of a library changes should be simply a matter of configuration. Since I don't know what ETL is (and I'm too lazy to Google) I can't say how to get that into a library. Still, you could simply take the webservice (sharepoint has those), upload it and mail some list yourself.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
And BTW: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Use C# and the SharePoint client side object model (CSOM).
If you get it right the first time, it should take about a month to build.
|
|
|
|
|
Gerry Schmitz wrote: it should take about a month to build I could do it in half that time, with twice the amount of bugs
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Using the samples, yes. A new or existing data model? Maybe. No SharePoint experience? Good luck.
|
|
|
|
|
..wasn't intended seriously, but since I also confuse them often, a serious response;
Gerry Schmitz wrote: Using the samples, yes. Ofcourse.
Gerry Schmitz wrote: A new or existing data model? Maybe. If you change the specs, then either the deadline or the price moves.
Gerry Schmitz wrote: No SharePoint experience? Some, that is why I said "twice the bugs".
Your chances of a succesfull demo in that case would equal zero; "some" means that there is always a prominent bug during a demo.
..and a similar big one right after the first release
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I was being rhetorical and not addressing anyone in particular
Just saying there are other considerations like data integrity, external user authorization, error handling and recovery, SharePoint "lists" maintenance ... which are all reflected in the code base.
|
|
|
|
|
I've had no problem in the past using WCF's DataContract/DataMember Attributes and serializing to XML with complex objects, including generic Dictionaries. But, after a few hours of reading up on WCF serialization, and reading posts on the usual places, I am stuck.
Here's a (down to the bare-bones for the sake-of keeping this short, .NET 4.5 code) example illustrating what I am trying to do.
using System;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.IO;
namespace WhatEver
{
public interface ISomeInterface
{
DateTime Date { set; get; }
}
public class BunchOfISomeInterface : Dictionary<Type, List<ISomeInterface>>
{
}
[DataContract]
public classLite : ISomeInterface
{
[DataMember]
public DateTime Date { set; get; }
}
[DataContract]
public classRegular : ISomeInterface
{
[DataMember]
public DateTime Date { set; get; }
[DataMember]
public extraString { set; get; }
}
public static class WriteMe
{
private static DataContractSerializer serializer;
static string filepath = @"C:\test.xml";
public static void Write(BunchOfISomeInterface bunch)
{
using (FileStream writer = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write))
{
serializer = new DataContractSerializer(typeof(BunchOfISomeInterface));
serializer.WriteObject(writer, bunch);
}
}
}
} If you call/use the above code using this in some .NET Class:
using WhatEver;
private void SomeTestClass()
{
BunchOfISomeInterface currentBunch = new BunchOfISomeInterface();
Lite lite1 = new Lite();
lite1.Date = DateTime.Now;
Regular regular1 = new Regular();
regular1.Date = DateTime.Now;
regular1.extraString = "extra";
currentBunch.Add(0, new List<ISomeInterface>());
currentBunch[0].Add(lite1);
currentBunch.Add(1, new List<ISomeInterface>());
currentBunch[1].Add(regular1);
WriteMe.Write(currentBunch);
} You'll get this error:
"An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.dll
Additional information: Type 'WhatEver.Lite' with data contract name"
I've tried several things here:
1. putting the [DataContract] Attribute on BunchOfISomeInterface: that gives an error that Bunch... cannot be serializable.
2. putting [DataContract] [KnownType(typeof(BunchOfISomeInterface))] Attributes on WriteMe: doesn't change the error.
3. I tried changing the ISomeInterface to be a Class rather than an interface: same error; that surprised me:
[DataContract]
public class ISomeInterface
{
[DataMember]
public DateTime Date { set; get; }
} That results in the same error message.
This thread on StackOverFlow suggests that you can't serialize Interfaces: [^], but I am not at a level with C# that I can grok if that's relevant here.
In other experiments I am getting the error: "Type 'System.RuntimeType' with data contract name"
thanks, Bill
«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.
modified 14-Sep-15 11:18am.
|
|
|
|
|
I don't know WCF, nor the DataContract, but..
..as which type of Duck would I deserialize an IFlying interface?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi, Eddy, thanks for the "moral" support
Once you start using WCF's DataContract and DataMember Attributes to serialize/de-serialize, I predict you'll have a mighty "aha" moment, and never use any other technique. Just, as I found out the hard way, never think about using them to serialize some data collection of instances of an Interface.
By using the 'EmitDefaultValue option on the Attribute
[DataMember(EmitDefaultValue = false)]
public string OriginalValue { set; get; }
You can control whether the serialized file will contain, or omit, writing any description of a field if the field's value is the default value for that Type.
cheers, Bill
«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.
|
|
|
|
|