|
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
}
|
|
|
|
|
|
|
hi ever one
please help me
i want get current keyboard language assume my os has two language (en,fa)this following code return Current cultural info i want keyboard current language not cultural info
private class State
{
public CultureInfo Result { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture.ClearCachedData();
var thread = new Thread(
s => ((State)s).Result = Thread.CurrentThread.CurrentCulture);
var state = new State();
thread.Start(state);
thread.Join();
var culture = state.Result;
MessageBox.Show(culture.ToString());
}
|
|
|
|
|
|
Doesn't Thread.CurrentThread.CurrentUICulture.DisplayName give you what you need to know ? Or, are you after reading low-level keyboard hardware capabilities ?
“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
|
|
|
|
|
Hello All,
I have a situation here where in i have to concatenate an icon to the label text based on some information.
As we have already set the image property i cannot go ahead with the image align property as it will align the image attached to the image property.
I am trying here to add an icon or image to the end of the text.
Thanks in Advance
Bharath s Ron
|
|
|
|
|
class Program
{
static void Main(string[] args)
{
using (var f = new Form())
{
var lbl = new Label();
lbl.Text = "Hello world";
lbl.Image = f.Icon.ToBitmap();
lbl.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
f.Controls.Add(lbl);
f.ShowDialog();
}
}
} Ron.bharath wrote: i cannot go ahead with the image align property as it will align the image attached to the image property. That's what you asked; put the image in the label, on the right side of the text. If you want something else, you'd have to specify 'what' you want a bit more clearly.
You could add a PictureBox on the right next to the label (concatenating controls, not data), but that would be less efficient.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Upvoted. Good answer: I had assumed the OP found that using the Image property of the Label, and ContentAlignment, didn't meet his needs, which may not be the case, here.
“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
|
|
|
|
|
At design-time you have several choices ... if your Label, and whatever graphic element object, is going to remain the same size at run-time no matter how its containing Control, or Form, is re-sized, and if your Label content, and the graphic content object, is not going to change:
1. you can position the Icon, or PictureBox, over the end of the Label Text.
2. you could create a custom UserControl combining a Label and a graphic element object, and design it to look "right."
If you are talking about creating text, and a graphic element, at run-time, or having text, or graphic, that changes at run-time, the problems of alignment become significant.
You can, in fact, insert a graphic object into the Controls Collection of a Label (or other Win Forms Control); you can't do that at design-time unless you modify the Designer.cs file yourself, which is not something recommended to do.
Once you have a graphic element "inside" a Label's DisplayRectangle, you may have the same problems of alignment/positioning you would have at design-time.
An alternative you could consider would be using a RichTextBox instead of a Label, where the insertion of graphic elements ... while not simple ... is more straightforward in that they can be placed in the "flow" of the text layout, and, in a RichTextBox calculation of the co-ordinates of the current end of the text content is much easier.
What have you tried so far ? And, is what you need to do to be done at run-time with changing content for both Label Text, and the related graphic element ?
“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
|
|
|
|
|