|
What is the latest C# version? is it same as the .net version number??
ie C# comes with .net4.0 is C#4.0. Is it like that?
My small attempt...
|
|
|
|
|
Latest version of c# is 4.0.
Yes, you are right, c# 4.0 comes with Visual Studio 2010 (.Net Framework 4.0).
|
|
|
|
|
sujithkumarsl wrote: Is it like that?
For .Net 4.0 this is the case i.e. C# 4.0 comes with .Net 4.0. The CLR for this has also been given the version number 4.0.
However, C# 3.0 worked on CLR 2.0 and Framework 3.5.
So version numbers need not necessarily be same.
|
|
|
|
|
Thank you for the answers.... It was an interview question... i said the latest is C#4.0 but he was not convinced
My small attempt...
|
|
|
|
|
I'm relatively new to using DataSets and DataAdapters so I have a few questions...
Can someone explain to me exactly what the TableMappings property does in a DataAdapter? The MSDN doesn't quite explain it well enough for me.
If I have a dataset filled with a subset of data from a given table, can I call fill again on that same dataset to pull in more data from that same table? If so, can I just use the fill function again in the same way with a different command or what?
Thanks,
Sam.
|
|
|
|
|
Nevermind... I figured it out.
|
|
|
|
|
Good Afternoon,
I posted this in General Databases earlier, but am not sure if is instead a C# problem since I am actually writing an application, so I am posting it here as well.
I used a nice SQL insert/update program for years with MSSQL 2000, but was never able to get it past security to make it work with 2005. This weekend, out of frustration, I decided to take a shot at writing one of my own. In doing so, I attempted to list the databases that were on the server. I first tested the command in the Query analyzer and it worked fine, returning all the names of the databases. However, when I tried to use the exact same code in the application, every database name comes up as "master" in the array, so I cannot continue to propagate the tables without a named database. I cannot understand how the identical code can return different results in different places. Here is the code.
Appreciate your assistance....Thank you, Pat
string Sql = "SELECT name FROM sys.databases";
SqlCommand Comm = new SqlCommand(Sql, Conn);
SqlDataAdapter da = new SqlDataAdapter(Comm);
DataSet ds = new DataSet();
da.Fill(ds);
int cnt = ds.Tables[0].Rows.Count;
string[] dbs = new string[cnt];
for(int i = 0; i < cnt; i++)
{
dbs[i] = ds.Tables[0].Rows[0]["name"].ToString();
}
foreach(string s in dbs)
{
databases.Items.Add(s);
}
|
|
|
|
|
You may want to consider using SMO for this kind of stuff - see this[^] article.
/ravi
|
|
|
|
|
Ravi..thank you for answering my question. I did get that code to work, but I had to add another reference. Although it finally did work, there was a different problem, but before I could finish it, I (actually one of you guys) found the error in the original code...simply replacing the string Rows[0] with Rows[i] fixed everything. I cannot believe I did not notice that! I am going to work on the other solution though, just in case I need to use at another time. Thank you again for your suggestion. Your time is appreciated! Best Regards, Pat
|
|
|
|
|
for(int i = 0; i < cnt; i++)
{
dbs[i] = ds.Tables[0].Rows[0]["name"].ToString();
} Wouldn't that stuff dbs with the first row?
for(int i = 0; i < cnt; i++)
{
dbs[i] = ds.Tables[0].Rows[i]["name"].ToString();
}
I are Troll
|
|
|
|
|
YES YES YES! Sometimes I am STUPID STUPID STUPID....I am looking right at it but still don't see it. Thank you for pointing this out. My mind must be someplace else. I appreciate your clear and accurate observation AND I have marked your answer as correct. The rest of the code is perfect and the app is working as designed. Best Regards, Pat
|
|
|
|
|
PDTUM wrote: I am looking right at it but still don't see it.
Take a long essay and have someone change a single character; it'll be very hard for your mind to register the typo, because your brain will try to correct what it sees. Once you know what word is expected, the brain only registers the word and no longer the individual letters.
PDTUM wrote: the app is working as designed
Wish I was too
I are Troll
|
|
|
|
|
Hello everyone ,
i am designing an image annotation tool .
In any image annotation tool , it enables you to drag a rectangle which for example shows an image , text or any other stuff inside of it , then when you click and drag the rectangle resizes itself accordingly over the shown image .
The question is :
which is the best programming practice for this task ???? , is it either to create a rectangle and keep track of the x,y coordinates and change the size of the rectangle accordingly ????
or
to inherit from the CONTROL Class and implement its methods like onMouseDown , OnMouseMove ....etc ????
Second thing ..... :
i need to know how can i place handles surrounding the rectangle ? and enable the user to change its Size according to its movement either to the right , left , top or bottom .?????
any help or existing examples to see ...
Any help will be greatly appreciated....
Thank you
Human knowledge belongs to the world.
|
|
|
|
|
I would be tempted to create a rectangle control here. The interaction logic for sizing/moving the rectangle would be contained in this class, then all your image control would need to do would be to hold references to the rectangle. The rectangle drawing could implement a simple handle drawing algorithm which drew a square at the corners.
If you want to see some sample code that does this, you can take a look at the Netron library here[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Netron Library couldn't be downloaded ..
if you have it , please send me a working download link .
so for good programming practice, you recommend me to create a rectangle object not to inherit from the control class and do the work inside ???? did i understand you correctly ?
Human knowledge belongs to the world.
|
|
|
|
|
You did. If the link isn't working there, there's a version on Sourceforge[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
When in doubt, I'm inclined to not use Controls and create my own classes of visible, drawable, movable parts. Takes some more code, but leads to snappier behavior as soon as you need lots of them. It also could offer more functionality, e.g. an easier selection of objects (select nearest, select by clicking through hollow shapes, etc).
As I understand your requirements (only a few controls involved), it wouldn't matter much, provided you don't get into transparency problems.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I believe you're looking for a C# version of a CRectTracker [^]. See this[^] article.
/ravi
|
|
|
|
|
Hello everybody!
I developed (up to alpha stage, at this moment) a picture browsing application for .NET 2.0 and released it under GPL v3.
Explanatory article
Google Code page
I tried to execute it on Mono to no avail. Even though the application runs, certain features do not work as expected, especially key presses and the full screen mode.
I also tried compiling it with Mono's C# compiler using Monodevelop. Although the compilation completed successfully, the newly-built application simply crashed on load.
After searching on the Mono project page, I found out that Windows Forms in the latest Mono version is considered to be 100% compatible with the corresponding MS implementation. Still, my Winforms app simply refuses to run correctly on Ubuntu, while running as expected on Windows.
Does anyone know of possible fixes to my emerging program, outside of shifting to GTK#?
All the best,
Mihnea
modified 20-Aug-18 21:01pm.
|
|
|
|
|
Mihnea Radulescu wrote: the latest Mono version is considered to be 100% compatible with the corresponding MS implementation
Ha ha ha ha ha ha....
I've not tried it for winforms, but did fairly extensively for ASP.NET, and found the compatibility to be well under 100% - maybe 95% at best. Unfortunately, it's the little bits that either don't work at all or are slightly different enough to crap your app out - understandable as it's not a paid development, and the coders have presumably got it working enough to support their code then said "That'll do".
Create a new project.
Import a bit of your existing code.
Test it under windows.
Test it again under mono.
Fix the broken bits.
Repeat.
Import a bit more code.
et., etc.
Good luck!
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
Hello everyone,
I am trying to use some managed code with some unmanaged rendering functions using OpenGL. I have a C# bitmap and I am trying to use OpenGL functions to draw on this bitmap.
Currently, my problem is that I am unable to initialize OpenGL and it fails with the error "Attempted to read or write protected memory. This is often an indication that the other memory is corrupt".
My OpenGL initialization routine is as follows (this is implemented as a C++ DLL function):
extern "C" __declspec(dllexport) BOOL InitGL(HDC * hdc,
HGLRC * hglrc)
{
BOOL retval = FALSE;
PIXELFORMATDESCRIPTOR pfd;
int format;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat(*hdc, &pfd );
retval = SetPixelFormat(*hdc, format, &pfd);
*hglrc = wglCreateContext(*hdc);
return retval;
}
The important bit here is the use of PFD_DRAW_TO_BITMAP and PFD_SUPPORT_GDI. I have tried drawing directly to window (using PFD_DRAW_TO_WINDOW) and that works ok.
It is called from C# as follows (I am omitting the DLLImport sections here and just focussing on the call).
Additionally, _bitmap is the bitmap object that I want to draw on.
try
{
Graphics graphics = System.Drawing.Graphics.FromImage(_bitmap);
IntPtr hDC = graphics.GetHdc();
if (!native_init)
{
NativeMethods.InitGL(hDC, out this._hglrc);
native_init = true;
}
}
finally
{
}
I thought that maybe I need to lock the bitmap data and I tried the following:
try
{
BitmapData bitmapData = _bitmap.LockBits(
new Rectangle(0, 0, _bitmap.Width, _bitmap.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
Graphics graphics = System.Drawing.Graphics.FromImage(_bitmap);
IntPtr hDC = graphics.GetHdc();
if (!native_init)
{
NativeMethods.InitGL(hDC, out this._hglrc);
native_init = true;
}
}
finally
{
_bitmap.UnlockBits(bitmapData);
}
However, this fails with the same error. I am not sure how I can use this locked bitmap data to initialize the OpenGL context.
Any help here would be really appreciated. I have spend hours looking at this and trolling the net to no avail now!
Thanks,
Keith
|
|
|
|
|
Ok, I fixed that problem. So, there were two issues:
First, I had to call ReleaseHdc on the graphic object.
Secondly, the HDC parameter should have been declated as an 'out' parameter.
However, there is another problem. However, this is more related to OpenGL and probably not suitabvle for this forum.
Thanks,
Keith
|
|
|
|
|
I have been studying C# for 6 months now. Perhaps I should have but I haven't yet run into the use of var for implicit variables and - in the following example - the subsequent replacing of parentheses with braces for enclosing the parameters.
var viewModel = new StoreIndexViewModel {
NumberOfGenres = genres.Count(),
Genres = genres};
I assume there is a particular reason for this? Any help would be appreciated. Thanks.
Darrall
|
|
|
|
|
This feature of C# is known as "Object Initializers".
Read about it here or on msdn.
|
|
|
|
|
Thanks
|
|
|
|