|
Not exactly a difficult thing to do: it is pretty common:
Using your original code:
public class Matrika
{
public int[,] arrayOfInts;
public Matrika(int x, int y)
{
arrayOfInts = new int[x, y];
}
}
static void Main(string[] args)
{
Matrika polzisce = new Matrika(5, 5);
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
Console.WriteLine(polzisce.arrayOfInts[x, y]);
}
}
} Note that it is not considered good practice to declare the array as public: I did this only to simplify this example.
Note also that the ints are not initialised, so they will all be zero.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thanks!
i have solved this thing it is realy preety simple
<br />
public class Matrika<br />
{<br />
public int mat_x;<br />
public int mat_y;<br />
public Array matrika;<br />
<br />
public Matrika(int x, int y)<br />
{<br />
mat_x = x;<br />
mat_y = y;<br />
matrika = Array.CreateInstance(typeof(int), x, y);<br />
{<br />
But, why did you say that public atributes are no ok?
|
|
|
|
|
av7254 wrote: why did you say that public atributes are no ok
This may take a little while to explain:
Assume you have a class: MyClass which contains a string and an int.
public class MyClass
{
public string UserName;
public int UserID;
....
}
You write your class, you test it, you are happy it works.
So happy, you use it to handle all the user identity work in your entire app!
Then the boss comes along, and says he wants the user name to be in two parts in the database: First name, and second name. Oh, and the userID is not an int, it's going to be a GUID.
How many classes do you have to change to implement this? How much code to you have to change, and test, and document?
If instead you had written the class as:
public class MyClass
{
private string userName;
public string UserName
{
get { return userName; }
set { userName = value; }
}
private int userID;
public int UserID
{
get { return userID; }
set { userID = value; }
}
}
When your dumb boss comes along with his changes, how much rework is there to do? Only the one class, because you can change the internals of MyClass without affecting the outside world:
public class MyClass
{
private string firstName;
private string lastName;
public string UserName
{
get { return firstName + " " + lastName; }
set
{
string[] names = value.Split(' ');
if (names.Length != 2)
{
throw new ApplicationException("Name must have first and last components");
}
firstName = names[0];
lastName = names[1];
}
}
private GUID userID;
public int UserID
{
get { return userID.GetHash(); }
set { userID = GetGUID(value); }
}
}
This is one of the cornerstones of OOP - encapsulation. Never expose your internals more than you have to!
When you are starting off, it seems like a lot of fussing about over nothing! But it very quickly becomes second nature, and does give real benefits - almost from day one. If nothing else, it forces you to think about how your class will be used, and what you want to expose to the outside world. Very often, this affects the internal design in a good way, by the realization that a small change in the original plan can give a more flexible class with wider applications. This leads to more code re-use, and thus better reliability.
I hope that made some sense!
[edit]userID changed to GUID in last example - forgot that when I cut and pasted[/edit]
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Maybe you should google encapsulation, since I think that is what your trying to do.
|
|
|
|
|
polzisce isn't two dimensional array..
matrika is two dimesional, and if you want to access it make it member of class and write a method..
|
|
|
|
|
jayantbramhankar wrote: matrika is two dimesional
No it isn't.
modified on Friday, March 19, 2010 3:41 PM
|
|
|
|
|
int[,] matrika = new int[x, y];
It's not? Granted, there is no word "dimesional", but it seems 2D to me.
|
|
|
|
|
Sorry, I didn't see the lowercase m.
|
|
|
|
|
So, how do i make it member of class, that will conatain x=5 and y=5 in this case.
"polzisce" has to be object wich contains a 2d array wich is specified with this Matrika polzisce = new Matrika(5,5);
Tnx for your answers
|
|
|
|
|
I'm still not sure what you want, but how about this:
public class Matrika
{
private readonly int x ;
private readonly int y ;
public Matrika
(
int X
,
int Y
)
{
this.x = X ;
this.y = Y ;
return ;
}
public int[,]
GetArray
(
)
{
return ( new int [ this.x , this.y ] ) ;
}
}
Matrika m = new Matrika ( 5 , 5 ) ;
int[,] polzisce = m.GetArray() ;
|
|
|
|
|
Hello,
I already use a graphic library (named Irrlicht) with a C# package called Irrlicht.NET (with a file Irrlicht.NET.dll and Irrlicht.NET.xml)
The libary is open source, and has recently delivered a new release.
But the .NET package has not been released (done probably by an other team)
How can I build the new release for C# .net ?
Best regards.
|
|
|
|
|
pedefetoll wrote: How can I build the new release for C# .net
How do you build the C++ code base to use with C#? Or, how do you get the C# source and build it? Did you ask the Irrlicht developer team?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
The C++ code with project files is full available on following site :
(see at http://irrlicht.sourceforge.net/downloads.html)
But I don't know how to convert documented C++ API for managed application (like MS C#).
Best regards
|
|
|
|
|
pedefetoll wrote: convert documented
Ah. You do not want to do that. What you would have to do is to go through the source line by line and translate it to its C# equivalent. Probably a big task. I think that what you really want to do is to take the C++ DLL and use it in your C# project. The keyword you are looking for is P/Invoke. Plenty of articles around that show you how to do that.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Hi All,
I have two C# windows application, both are reading .csv file and doing some processing, however there is one difference between both .csv file. One .csv file is using comma (,) as delimiter (separater) and other .csv file is using |(Pipe) character as delimiter (separater), so basically that is customized seperater.
Both .csv file is used by my two different C# windows application.
Now here is a problem.
My first application used .csv file which has comma(,) as seperater and i am using provider as "Microsoft.Jet.OLEDB.4.0" to reading that file with following connectionstring:
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvfile.Directory.FullName + ";Extended Properties='text;HDR=Yes'";
As by default it's comma, so i don't have to do any changes in my registry to read this file, it's simple but problem came when i am using my other C# windows application.
Second C# windows application is using other .csv file which has |(Pipe) character as seperater(delimiter). To read this type of .csv file i used following connection string
string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';";
As well as in the registry i specified (|) delimiter at following place:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text
i defined "Format" = "Delimited(|)" and second C# application able to read .csv file in correct way but now the problem is that it screwed up my first C# application as it is using comma as seperater.
Is there a way to define multiple custom delimiter under registry setting at following place
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text
like Delimited("|",",") etc or some thing like that??
I tried that but it didn't work.
My questions are :
- how can my both C# application should work without effecting each other?
As i said , one is having comma(,) as sepearter(delimiter) in .csv file and other is having (|) pipe as sepearter, how can my two different application can work at it's own without effecting each other?
- Currently as i defined delimited(|) in above mentioned registry setting so it screwed up first application and my first application is NOT able to read .csv file (which has comma(,) as delimiter)
- Is there a way to define Multiple delimiter in registry settings at above mentioned location at registry?
I don't want to use scheme.ini file at all.
Pls. help me out to resolve this issue.
Thanks in advance.
|
|
|
|
|
montu3377 wrote: delimiter under registry
Do you have to use the registry? There are easier/better ways to accomplish this other than using a registry setting.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Hi,
Can you tell me what are easier ways? I am using following code :
//Taking connection using to .csv file
string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';";
//assigning to oledbconnection string
OleDbConnection conn = new OleDbConnection(textConnectionString);
// Opening connection
conn.Open();
//selecting rows from .csv file
sql_select = "Select * from " + InputCSVFile.ToString().Trim() ;
//Creates the data adapter
OleDbDataAdapter obj_oledb_da = new OleDbDataAdapter(sql_select, conn);
//Fills dataset with the records from CSV file
obj_oledb_da.Fill(ds);
As i have (|) pipe character in my .csv file , so i am specifying (|) pipe sepearter in registry setting otherwise i will NOT get correct parsed values.
Pls. let me know if you have some other way rather than this way??
I am eager to seeing that.
Thanks a lot for reply.
|
|
|
|
|
montu3377 wrote: way rather than this way
Take a look at this article, A Fast CSV Reader[^] and see if that is fills your need. You can use whatever delimiter you want.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Is to use different extensions for your file types to determine whether a pipe or a comma is used as the delimiter.
|
|
|
|
|
I don't think I've ever heard of anyone using the Jet engine to read a CSV file.
Most people just read and Split the lines.
|
|
|
|
|
Using Jet (or ACE) is pretty useful because you can use the ADO.Net classes to work with the data instead of manually parsing. It's especially useful for more complex CSVs that have "Excel-friendly" fields similar to
"=""Value""""WithQuotes"""
|
|
|
|
|
If you want to continue using the Jet engine to read in your pipe delimited file then you are going to have to use a schema.ini file as the registry can only be use for a single delimiter value or, use the article Wes linked to and drop using the Jet engine.
|
|
|
|
|
i have created an object at client side and update it some properties values and pass it to the server, to save the object data in database.
Object data is saving correctly and the some properties is also updating at server side of passing object. but when we access the object at client side
then client properties does not update.
so how can we work as reference object between client and server in remoting, means if we update the object properties at server side, then it should show the changes at client side also?
|
|
|
|
|
The only way to do this is to transmit the changes back again. As you are aware, your changes have been made in a separate app process, so they aren't visible. Possibly the "easiest" way to do this would be to raise an event at the server side, which returns the changes to the client.
Search for .net remoting events to find some articles on this because it's not as simple as just coding an eventhandler. Remote events need marshalling too, so you'll need to get a thorough understanding to accomplish this.
BTW - this is also known as a callback.
"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
|
|
|
|
|
Hi, I'm a newbie in drawing using C#.
I want to create a filled cylinder or a tube.
So what I do is I created a closed curve using 4 points (using FillClosedCurve) with 0.8f tension. Then I translated the same closed curve vertically to create a sense of height. But then how do I fill the sides?
Here is an image to illustrate my explanation: http://img692.imageshack.us/img692/9461/100319codeprojectquesti.png[^]
Thanks for any help.
|
|
|
|