|
i didn't know SortedDictionary<tkey, tvalue="">.I'm searching for information in internet.Is it the right way?
Thank you
|
|
|
|
|
Whether a SortedDictionary, or a SortedList, is "right," depends on the requirements of your code.
Does the solution you are creating require frequent immediate access to a sorted collection of data, and is that data "coming in" in a way where it's "unsorted" ?
If that's the scenario, then perhaps you are required to sort the data every time you add a new item to it.
On the other hand, if your need for access to sorted data is intermittent, perhaps you'll get better performance if you sort on demand.
Keep in mind that a SortedList is a collection of Key/Value Pairs, and there is a cost in memory, and computation, for maintaining it compared to a simple Generic List, just as there is for using a SortedDictionary.
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : 'I know all about it. I've already found it.'
As far as I'm concerned, the word means: 'I am looking. I am hunting for it. I am deeply involved.'”
Vincent Van Gogh
|
|
|
|
|
You need to be clear what you mean by "ordered with its string value" (at least for folks like me who don't use Python).
If you mean sort alpha-numerically, then YourList.Sort(); will take care of that for you in .NET C#.
If you doing some kind of ordering beyond the default ("natural" ordering of elements based on their Type), then, if you are using C# 2.0, not 3.0, that's is important to know, also.
Also of interest is whether you are sorting in-place, or perhaps wish ... using Linq ... to return a new List sorted/ordered-by whatever without changing the source List.
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : 'I know all about it. I've already found it.'
As far as I'm concerned, the word means: 'I am looking. I am hunting for it. I am deeply involved.'”
Vincent Van Gogh
|
|
|
|
|
Sorry.I need to create a sorteddictionary or a sortedlist to have my items ordered by the key "dot" that is a guid .in python you don't need that,you only create a list with different types and it is ordered.thank you anyway
|
|
|
|
|
If you need to use a Dictionary, then something like Dictionary<Guid,string> should be fine.
For a discussion of issues with sorting a Dictionary, see this thread that I started in November, this year: [^].
Using a generic List would allow for more than one list item with the same value; using a Dictionary you must have a unique Key for each item, but you can have multiple items with the same Value. What exactly is required ?
If you choose to use a SortedDictionary, or SortedList, you may wish to do some research on their differences; the best single summary of that I know is:[^].
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : 'I know all about it. I've already found it.'
As far as I'm concerned, the word means: 'I am looking. I am hunting for it. I am deeply involved.'”
Vincent Van Gogh
modified 27-Dec-13 19:07pm.
|
|
|
|
|
thank you very very much for you explanation.i think i will use SortedList .the reason is that i always have different keys because they are Guid and a string value for each key ("fix" or "free").then i think it is easy to change the value of some keys when needed,and to iterate ,to remove elements etc etc.i only have to use casting for the keys.thank you very much again .you have been very kind
|
|
|
|
|
Hi all.i tried to use SortedList but unfortunatly it didn't meeet my needs.It is too difficult to make my object implementing icomparable.In the end i preferred to use two normal List,one for my dots and the other for the associated string The number of elements in both lists is the same and i only have to remember to update both of them when adding or removing elements from one of the lists.they are linked by the index of elements and everithing is easyer and faster.However, thanks for your advices
|
|
|
|
|
Somebody some can help me as C#beginners. I want calculate properties of rectangle.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vererbung
{
class Rechteck
{
private double laenge;
private double breite;
struct Parameter
{
private double breite;
private double laenge;
public Parameter(double laenge, double breite)
{
this.breite = breite;
this.laenge = laenge;
}
}
public double getLaenge() { return laenge; }
public double getBreite() { return breite; }
public double getUmfang()
{
return 2 * laenge + 2 * breite;
}
public double getFlache()
{
return laenge * breite;
}
public double getDiagonale()
{
return Math.Sqrt(laenge * laenge + breite * breite);
}
static void Main(string[] args)
{
Console.WriteLine("Gib die Länge vom Rechteck: ");
string l = Console.ReadLine();
Console.WriteLine("Gib die Breite vom Rechteck: ");
string b = Console.ReadLine();
Rechteck obj = new Rechteck();
obj.laenge = 0;
obj.breite = 0;
Console.WriteLine("Rechteck Länge: " + l + "\nRechteck Breite: " + b);
Console.WriteLine("Die Diagonale beträgt: " obj.getDiagonale(l, b));
Console.WriteLine("Der Umfang beträgt: " obj.getUmfang(l, b));
Console.WriteLine("Die Fläche beträgt: " obj.getFlache(l, b));
}
}
}
|
|
|
|
|
You are creating methods called getXXX instead of using properties. See http://msdn.microsoft.com/en-us/library/aa288470(v=vs.71).aspx[^] and modify your class with properties such as:
public double Flache
{
get
{
return laenge * breite;
}
}
You are also trying to pass parameters to methods that do not take any. You should write a constructor that accepts the length and width and then create a new object with those details like:
Rechteck obj = new Rechteck(l, b);
Veni, vidi, abiit domum
|
|
|
|
|
There are several errors in the code in your Main method:
1. you don't convert the user-entered values for length, and width, from string to integer, and assign them to the variables 'l and 'b in the instance of the Class 'Rechteck.
2. you left out the required + string concatenation operator in the three lines that call your functions to calculate diagonal, perimeter, and area.
3. you call the functions to calculate diagonal, perimeter, and area with arguments when the functions have no parmeters.
Try this:
static void Main(string[] args)
{
Console.WriteLine("Gib die Länge vom Rechteck: ");
string l = Console.ReadLine();
Console.WriteLine("Gib die Breite vom Rechteck: ");
string b = Console.ReadLine();
Rechteck obj = new Rechteck();
obj.laenge = Convert.ToInt32(l);
obj.breite = Convert.ToInt32(b);
Console.WriteLine("Rechteck Länge: " + l + "\nRechteck Breite: " + b);
Console.WriteLine("Die Diagonale beträgt: " + obj.getDiagonale());
Console.WriteLine("Der Umfang beträgt: " + obj.getUmfang());
Console.WriteLine("Die Fläche beträgt: " + obj.getFlache());
Console.ReadLine();
}
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : 'I know all about it. I've already found it.'
As far as I'm concerned, the word means: 'I am looking. I am hunting for it. I am deeply involved.'”
Vincent Van Gogh
|
|
|
|
|
using System;
namespace Vererbung
{
class Rechteck
{
double laenge;
double breite;
public double getUmfang()
{
return 2 * laenge + 2 * breite;
}
public double getFlache()
{
return laenge * breite;
}
public double getDiagonale()
{
return Math.Sqrt(laenge * laenge + breite * breite);
}
static void Main(string[] args)
{
Console.WriteLine("Gib die Länge vom Rechteck: ");
double l =double.Parse( Console.ReadLine());
Console.WriteLine("Gib die Breite vom Rechteck: ");
double b = double.Parse( Console.ReadLine());
Rechteck obj = new Rechteck();
obj.laenge = l;
obj.breite = b;
Console.WriteLine("Rechteck Länge: " + l + "\nRechteck Breite: " + b);
Console.WriteLine("Die Diagonale beträgt: "+ obj.getDiagonale());
Console.WriteLine("Der Umfang beträgt: "+ obj.getUmfang());
Console.WriteLine("Die Fläche beträgt: " +obj.getFlache());
Console.ReadLine();
}
}
}
|
|
|
|
|
Thanks so much, I was trying many hours - now I have a very nice example to create objects and do something within.
|
|
|
|
|
 Sorry I do something wrong - can somebody explain how I can build in structor "Position" right to print object "Starrflügelfugzeug" on CMD-screen
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lektion4
{
struct Position
{
public int x, y, h;
public Position(int x, int y, int h)
{
this.x = x;
this.y = y;
this.h = h;
}
public void PositionÄndern(int deltaX, int deltaY, int deltaH)
{
x = x + deltaX;
y = y + deltaY;
h = h + deltaH;
}
}
class Luftfahrzeug
{
protected Position pos;
protected string kennung;
public Luftfahrzeug() { }
public Luftfahrzeug(string kennung, Position pos)
{
this.kennung = kennung;
this.pos = pos;
}
public void Steigen(int meter)
{
pos.PositionÄndern(0, 0, meter);
Console.WriteLine(kennung + " steigt " + meter + " Meter, neue Höhe=" + pos.h);
}
public void Sinken(int meter)
{
pos.PositionÄndern(0, 0, meter);
Console.WriteLine(kennung + " sinkt " + meter + " Meter, neue Höhe=" + pos.h);
}
}
class Starrflügelflugzeug : Luftfahrzeug
{
public Starrflügelflugzeug() : base("kennung", ???) { }
}
class Program
{
static void Main(string[] args)
{
Luftfahrzeug flieger2 = new Luftfahrzeug("LH 3333", new Position(105020, 30800, 110));
flieger2.Steigen(100);
Luftfahrzeug flieger1 = new Luftfahrzeug("LH 3333", new Position(105020, 30800, 110));
flieger1.Sinken(50);
Starrflügelflugzeug flieger3 = new Starrflügelflugzeug("LH 3333", ???);
flieger3.kennung = "LH 3333";
flieger3.pos = new Position(105111, 30811, 130);
flieger3.Sinken(50);
}
}
}
|
|
|
|
|
I need to create a onenote-page which contains a number of hyperlinks to files on the disk or perhaps network-share). The generating of the ON-page is no issue anymore, this will work coorectly. Even the list of files on a specific directory is no problem at all.
My issue is generating a working hyperlink: I tried several pieces of code, but every time the same "error" will result in not creating a hyperlink. My current piece of code looks like this:
sb.AppendLine(string.Format(string.Format("<ahref=\"onenote:Project%202.one#base-path={0}\">...</a>",
Path.GetFullPath(filePaths[x]))));
the output is < a href=\"onenote:Project%202.one#base-path=c:\\temp\\connectorLog.txt\">...< /a >\r\n"
the last backslash after "connector.txt" is used for escaping the double quetes, but should not be part of the filename. So the only thing I can see in the ON-page, are three periods in plain text and no hyperlink is created,
Can somebody help me a little??
|
|
|
|
|
I don't know what this question has to do with C#, but when I paste a link into OneNote it is stored 'as is' not in HTML form.
Veni, vidi, abiit domum
|
|
|
|
|
I create this link in a self made Onenote Add-in with C#. Sorry I should mention it in my opening post. I generate a coupe of hyperlinks to files on the hard disk.
|
|
|
|
|
That does not help to explain why it does or does not work. The issue is with OneNote, not with C# code, as far as I can see.
Veni, vidi, abiit domum
|
|
|
|
|
as you can see, the last backslash is my bottleneck. There is no valid hyperlink created in C#. When I manipulate sb by hand it still doensn't work so I assume it's a C# issue
|
|
|
|
|
I see no such thing, and I also see nothing that points to a C# problem. You need to provide a lot more detail of exactly what your code is doing.
Veni, vidi, abiit domum
|
|
|
|
|
OK, I created an Add-in for OneNote. On a form I select a folder on my hard drive e.g. c:\temp. The next step is generating a list of all the files in this directory. I want to show the filenames in Onenote in a table on the left hand column. the right hand column should contain a hyperlink to this file so it opens automatically. The display-text of the link is always ... (three periods).
My code generates the table with the filenames correctly, but not the links on the right. I only see three periods with no link.
I think (pretty shure) it fails on qoutes, (back)slashes and stuff like that... When i take a look at the XML-source of the generated OnteNote-page, I only see the three periods in the CDATA-tag....
|
|
|
|
|
Might I suggest:
- Create a link (like the ones you want) manually in OneNote.
- Look at the generated text in the OneNote file
- Duplicate that operation.
Veni, vidi, abiit domum
|
|
|
|
|
I just looked at a section of a Onenote document with a Hyperlink and it appears in the file as <http://www.codeproject.com/Messages/4728201/Re-Generate-hyperlink-to-file.aspx> , not as an HTML anchor.
Veni, vidi, abiit domum
|
|
|
|
|
when I create a link on a page, it looks in XML-source just like this:
<one:T><![CDATA[</one:T>
|
|
|
|
|
This code works fine:
sb.AppendLine(string.Format("<a href=\"onenote:Project%202.one#base-path={0}\">...</a>", Path.GetFullPath("C:\\Windows\\CMD.exe")));
So my question is why two string.Format statements? The other thing to check is the filePaths[] array and make sure it doesn't have a \ at the end of some or all of the records.
Not sure why it isn't working but as has been stated, your c# code is good.
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
Hello,
I found this class in my research but I do not know how to use it. Moreover, it seems to me that the ConvertBack () method is not completely completed.If someone has already used his help will be invaluable for me.
here is the class
[ValueConversion(typeof(byte[]), typeof(ImageSource))]
public class ByteArrayToImageSource : IValueConverter
{
#region Implementation of IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var byteArrayImage = value as byte[];
if (byteArrayImage != null && byteArrayImage.Length > 0)
{
var ms = new MemoryStream(byteArrayImage);
var bitmapImg = new BitmapImage();
bitmapImg.BeginInit();
bitmapImg.StreamSource = ms;
bitmapImg.EndInit();
return bitmapImg;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
#endregion
}
|
|
|
|
|