|
You don't use the implicit var. You declare the sortedList as a List<ClassName> and then your query becomes:
sortedList = (from res in mResult
orderby res.field2
select res).ToList();
|
|
|
|
|
|
If you mean you already have an instance of List<mResults>, assigned to a variable say list...
list.Sort((i, j) => { return i.Field2.CompareTo(j.Field2); });
should work.
|
|
|
|
|
Actually, I think you mean your list is called mResults, so in that case I would do...
mResults.Sort((i, j) => { return i.Field2.CompareTo(j.Field2); });
|
|
|
|
|
This article[^] tells you how to do it without LINQ.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Nah. It's crap. Only kidding - it's a good article.
A small critique - the plural of criterion is criteria, so you have s singular of "the criterion is...", where the plural would be "Multiple sort criteria are easy to implement". A criterium is actually a bike race.
|
|
|
|
|
Thanks Pete.
In Dutch we use the Latin word criterium for both; English apparently has borrowed the Greek word κριτήριο; all fixed now.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I am confused with the process to export datagridview data to excel or pdf format. Could somebody help me on this please?
Thank you
|
|
|
|
|
I am sure there is no need to shout. To export data to excel look up
ADO.Net or
Excel Interop . to export data to pdf try iTextSharp library. In future you don't need to use bold letters. Most people in these forums can read quite fine.
|
|
|
|
|
For Excel, just put it on the clipboard. (DataGridView.GetClipboardContent.)
For PDF there is no obvious meaning for what you want, never mind a method to do it. PDF is a display format not a data table one. If you want to create a PDF which has within it some text and lines that makes it look like a table, you can do that yourself (or find a library that does it).
|
|
|
|
|
Hi,
I have two classes say Class A and Class B. I am trying to find how
do I get reference the loaded instance of Class A in Class B.
I do not want to get a new instance of Class A. I want to be able to
reference to the loaded instance and use the loaded methods and properties.
Class A
{
...
Class A myClass = New Class A();
...
...
Class B clsb = New Class B();
clsb.DoSomething(int a, int b)
}
Class B
{
...
public void DoSomething(int a, int b)
{
....
//I want to be able to reference to the loaded instance which is 'myClass' of the Class A. (not a new instance)
}
}
Can some one please help me with this.
Thanks,
L
.
|
|
|
|
|
|
ClassA should provide a static method or a static property which returns the instance created inside it. This method/property will help others access that instance.
|
|
|
|
|
If having a static reference (or the Singleton pattern, basically the same thing) is inappropriate, you could pass it in in the constructor or as a method parameter on class B.
I'm surprised this works, though - maybe it's the pseudo-code you've presented, but this:
public class ClassA()
{
private ClassA myClass = new ClassA();
}
is the same as:
public class ClassA()
{
private ClassA myClass = null;
public ClassA()
{
myClass = new ClassA();
}
}
Won't this end up with a stack overflow?
|
|
|
|
|
GlobX wrote: Won't this end up with a stack overflow?
Why not just run it and see for yourself. I guess it will.
|
|
|
|
|
It was more intended as a rhetorical question, like a "have you thought about this...?" 'sides, too busy hating on BizTalk to play around
|
|
|
|
|
GlobX wrote: hating on BizTalk
Just work on SharePoint as well and you have witnessed hell.
|
|
|
|
|
Pass it to the constructor or a property.
B b = new B() ;
A a = new A ( b ) ;
or
a.B = b ;
|
|
|
|
|
Hi,
You need to use the Singleton pattern to achieve this. Please find the example below
public class A
{
private static A _instance;
private A()
{}
public static A GetInstance()
{
if(_instance == nulll)
_instance = new A();
return _instance;
}
}
public class B
{
public void Somemethod()
{
A a = A.GetInstance();
.
.
.
do somethig
.
.
}
}
Note that we make the constructor of class A private. And class A holds a instance of itself in _instance variable. This is for to make sure that an out side method cannot create an instance of A. Then we will provide a static method in class A like GetInstance where we create a new instance if an instance is already not exist and return the current instance
Hope this helps
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
No, never a singleton, especially with .net languages; they're not needed and generally a symptom of poor design. I have never found a situation that wuold benefit from a singleton.
Nitheesh George wrote: cannot create an instance of A
In .net everyone has access to your privates.
And give this[^] a read.
|
|
|
|
|
Hi,
I want to separate number and date and time from a string in c#. here is an example:
+CMGR: "REC READ","+923365483536",,"10/09/15,08:16:11+20"
from this i want to put cell number in one array and date and time in another.I dont know how to do this.
Thanks for any kind of help in advance
Regards,
Aeman
|
|
|
|
|
Well, you could always use a string split on this based on the commas and take the array items at index 1 and index 3.
|
|
|
|
|
index 3 and 4!
I cannot remember: What did I before google?
|
|
|
|
|
So cell isn't stored in the bit +9....? Index 3 is an empty string in his example.
Nevermind - I see what you're saying. I'd missed the , in the date.
I'm not a stalker, I just know things. Oh by the way, you're out of milk. Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Onyx
modified on Tuesday, March 29, 2011 9:40 AM
|
|
|
|
|
You could use a regular expression but then you may end up with not one problem but two
using System.Text.RegularExpressions;
...
string txt = "+CMGR: \"REC READ\",\"+923365483536\",,\"10/09/15,08:16:11+20";
Match m = Regex.Match(txt, @"[0-9]{2}/[0-9]{2}/[0-9]{2},[0-9]{2}:[0-9]{2}:[0-9]{2}");
if(m.Success)
{
String date = m.Value.Replace(",", " ");
DateTime dt = DateTime.Parse(date);
}
The snippet above should work but you may want to refine the expression. I just hacked that one up quickly
"You get that on the big jobs."
|
|
|
|